nanogui: Possible bug in GrSendClientData?
Subject:
Re: [nanogui] Possible bug in GrSendClientData?
From:
"Greg Haerr" ####@####.####
Date:
1 Aug 2004 03:26:00 +0100
Message-Id: <0bef01c4776f$a23eb3f0$6401a8c0@gregnewport>
> Where is the memory allocated to 'p' in GrSendClient() free'ed? There is
> no free in GrSendClient() after the call to GsDeliverClientDataEvent().
I've reviewed the code, and yes, there's a big memory leak.
> I have limited knowledge of the nano-X code, but this looks like a
> memory leak to me. Is it? Shouldn't GrSendClient() code look like this?
>
> memcpy(p, data, thislen);
>
> GsDeliverClientDataEvent(did, wid, serial, len, thislen, p);
> free(p);
>
> SERVER_UNLOCK();
Actually, the GrSendClientData function shouldn't even malloc
data, since only calls GsDeliverClientDataEvent which mallocs
and copies again. Thus, the correct GrSendClientData implementation
should look like this:
SERVER_LOCK();
GsDeliverClientDataEvent(did, wid, serial, len, thislen, data);
SERVER_UNLOCK();
> Plus, I just noticed, in GrSendClient() memory of size 'len' is
> malloc'ed for p>b But, 'thislen' is used for the size of the memcpy.
> Shouldn't the malloc of 'p' be sized to 'thislen'?
Yep - but this isn't needed anymore with the above implementation.
Regards,
Greg