[sr-dev] Does shm_free() make the pointer NULL?

Ovidiu Sas osas at voipembedded.com
Tue Feb 28 20:24:34 CET 2012


You pass the value of a pointer, not the address of a pointer and
therefore it cannot be set to NULL.
You need to check if the shm_malloc is successful and before calling
shm_free, you should check the value of the pointer.
Also, it is always good to set the pointer to NULL after a shm_free to
avoid dangling pointers.

Regards,
Ovidiu Sas

On Tue, Feb 28, 2012 at 2:14 PM, Iñaki Baz Castillo <ibc at aliax.net> wrote:
> Hi, I'm realizing that a doble freeing occurs in regex module when it
> fails to start due to module params errors. But I'm sure it didn't
> occur in Kamailio 1.5. My question is the following:
>
>
>  static int *number;
>  number = shm_malloc(sizeof(int));
>  shm_free(number);
>
> Should now number be NULL? I confirm that it's NOT, so I get a double
> freeing since the function free_shared_memory() is executed twice and
> I check "if (number)" before doing "shm_free(number)".
>
> So is it a change in 3.X? should I write:
>
>  shm_free(number);
>  number = NULL;
>
> ?
>
> Thanks a lot.
>
> --
> Iñaki Baz Castillo
> <ibc at aliax.net>
>
> _______________________________________________
> sr-dev mailing list
> sr-dev at lists.sip-router.org
> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev



-- 
VoIP Embedded, Inc.
http://www.voipembedded.com



More information about the sr-dev mailing list