Joe Van Dyk
4/27/2005 4:35:00 PM
On 4/27/05, ts <decoux@moulon.inra.fr> wrote:
> >>>>> "J" == Joe Van Dyk <joevandyk@gmail.com> writes:
>
> J> I looked at the C code for the SysVIPC module but couldn't see any
> J> obvious errors.
>
> xcalloc() called without a free(), no ?
>
> Guy Decoux
>
>
I saw that. But I didn't see how it could be free'd (but my C-fu sucks).
Here's the relevant code:
============================
static VALUE
rb_msg_recv (argc, argv, obj)
int argc;
VALUE *argv, obj;
{
VALUE v_type, v_len, v_flags;
int flags = 0;
struct msgbuf *msgp;
struct ipcid_ds *msgid;
long type;
size_t rlen, len;
rb_scan_args (argc, argv, "21", &v_type, &v_len, &v_flags);
type = NUM2LONG (v_type);
len = NUM2INT (v_len);
if (!NIL_P (v_flags))
flags = NUM2INT (v_flags);
msgp = xcalloc (sizeof (long) + len, sizeof (char));
msgid = get_ipcid (obj);
retry:
TRAP_BEG;
rlen = msgrcv (msgid->id, msgp, len, type, flags);
TRAP_END;
if (rlen == (size_t)-1)
{
switch (errno)
{
case EINTR:
rb_thread_schedule ();
case EWOULDBLOCK:
#if EAGAIN != EWOULDBLOCK
case EAGAIN:
#endif
goto retry;
}
rb_sys_fail ("msgrcv(2)");
}
return rb_str_new (msgp->mtext, rlen);
}
============================
msgp is included in the return statement, so I'm not sure how it could
be free'd. Isn't its memory being used by the new Ruby string? And
shouldn't that memory be garbage collected at some point?
Joe