From: Joe Van Dyk Date: 2005-04-28T02:11:53+09:00 Subject: Re: memory leak On 4/27/05, ts wrote: > >>>>> "J" == Joe Van Dyk writes: > > J> Is that standard practice with Ruby extensions? > > Only the author of the extension know the response to this question ... > > Guy Decoux > > Thanks for your help. I think I fixed it. I haven't given it hugely extensive testing, but it fixes my problems. Essentially, I free'd everything that was xcalloc'd. Patch is below. I'm new to this whole patching/fixing thing business, so not sure if its in the right format or what. --- sysvipc.c.old 2005-04-27 09:54:17.000000000 -0700 +++ sysvipc.c 2005-04-27 10:03:52.000000000 -0700 @@ -209,6 +209,7 @@ rb_sys_fail ("msgsnd(2)"); } + free(msgp); return obj; } @@ -223,6 +224,7 @@ struct ipcid_ds *msgid; long type; size_t rlen, len; + VALUE return_str; rb_scan_args (argc, argv, "21", &v_type, &v_len, &v_flags); type = NUM2LONG (v_type); @@ -249,10 +251,13 @@ #endif goto retry; } + free(msgp); rb_sys_fail ("msgrcv(2)"); } - return rb_str_new (msgp->mtext, rlen); + return_str = rb_str_new(msgp->mtext, rlen); + free(msgp); + return return_str; } static void @@ -329,6 +334,7 @@ for (i = 0; i < nsems; i++) rb_ary_push (dst, INT2FIX (array[i])); + free(array); return dst; } @@ -351,6 +357,7 @@ array[i] = NUM2INT (RARRAY(ary)->ptr[i]); semctl (semid->id, 0, SETALL, array); + free(array); return obj; } @@ -463,6 +470,7 @@ if (semop (semid->id, array, nsops) == -1) rb_sys_fail ("semop(2)"); + free(array); return obj; }