From: Eric Wong Date: 2015-10-27T22:12:58+00:00 Subject: [ruby-core:71232] Re: [Ruby trunk - Bug #11626] [Open] fprintf in c extension keep adding memory usage guchen.yang@fugawi.com wrote: > fprintf will keep adding memory usage without releasing it. > > I was doing it in rails console, not sure if it makes any different. The code like this: > > VALUE leak (VALUE self, VALUE in) { > char *str = StringValuePtr(in); > char *pstr; > pstr = malloc (10240); > strcat(pstr,str); pstr is uninitialized memory when you call strcat on it, likely screwing with how fprintf uses it. Does replacing the malloc + strcat with: pstr = strdup(str); help at all? > fprintf (stdout, pstr); > self = rb_str_new_cstr(pstr); > free (pstr); > return self; > }