On Tue, Apr 06, 2004 at 11:27:39AM -0700, hekaddr-reg (at) yahoo (dot) com [email concealed] wrote:
> Hi Frederic,
>
> "AL" is a structure of the following type:
>
> struct libnet_ifaddr_list
> {
> u_int32_t addr;
> int8_t *device;
> };
>
> So although "al" itself is static variable, its field "device"
> points to dynamically allocated memory (in this case, allocated
> by strdup()). Thus the old memory allocated for al->device need
> to be freed before new memory is allocated for al->device.
>
> In fact, parasoft's insure++ reports a memory leak at this strdup()
> which is where I come from.
>
> I did the following patch and it seems the "memory leak" is gone:
>
> [libnet_if_addr.c]
> 238
> + if (al->device) free(al->device);
> 239 if ((al->device = strdup(device)) == NULL)
> 240 {
> 241 snprintf(errbuf, LIBNET_ERRBUF_SIZE,
> 242 "%s(): strdup not enough memory\n", __func__);
> 243 return(-1);
> 244 }
>
> Hi Frederic,
>
> "AL" is a structure of the following type:
>
> struct libnet_ifaddr_list
> {
> u_int32_t addr;
> int8_t *device;
> };
>
> So although "al" itself is static variable, its field "device"
> points to dynamically allocated memory (in this case, allocated
> by strdup()). Thus the old memory allocated for al->device need
> to be freed before new memory is allocated for al->device.
>
> In fact, parasoft's insure++ reports a memory leak at this strdup()
> which is where I come from.
>
> I did the following patch and it seems the "memory leak" is gone:
>
> [libnet_if_addr.c]
> 238
> + if (al->device) free(al->device);
> 239 if ((al->device = strdup(device)) == NULL)
> 240 {
> 241 snprintf(errbuf, LIBNET_ERRBUF_SIZE,
> 242 "%s(): strdup not enough memory\n", __func__);
> 243 return(-1);
> 244 }
>
Oops ;-)
hekaddr-reg 1 - 0 Fred
Fred Raynal
[ reply ]