:: Re: [DNG] Pointer error in the back…
Pàgina inicial
Delete this message
Reply to this message
Autor: KatolaZ
Data:  
A: Rainer Weikusat
CC: dng
Assumpte: Re: [DNG] Pointer error in the backend of Netman
On Thu, Dec 10, 2015 at 05:59:04PM +0000, Rainer Weikusat wrote:
> Edward Bartolo <edbarx@???> writes:
>
> [...]
>
> > Realloc uses two parameters: the first is a pointer whose allocation
> > is to be modified/reallocated. The second is the NEW number of bytes
> > required. In the function line 240 is:
> > active_wifi_list = realloc(active_wifi_list, (((z - 1)/2) +
> > list_delta)*sizeof(void*));
> >
> > I should assume that the assignment is unnecessary although it works.
>
> The assignment is not uneccesary: On success, realloc returns a pointer
> to the new area and the old pointer becomes invalid. If the allocation
> can be extended in place, realloc may just return the old pointer,
> however, if it can't, it will return a pointer to some newly-allocated
> storage and the old will be freed.


....and finally, just to be pedantic again, realloc will return NULL
if it cannot allocate the requested amount of memory anywhere, so that
it is always better to check the return value before assigning it to
the old pointer, in order to avoid leaking memory and to produce an
unnecessary, unpleasant segfault.

HND

KatolaZ

--
[ Enzo Nicosia aka KatolaZ --- GLUG Catania -- Freaknet Medialab ]
[ me [at] katolaz.homeunix.net -- http://katolaz.homeunix.net -- ]
[ GNU/Linux User:#325780/ICQ UIN: #258332181/GPG key ID 0B5F062F ]
[ Fingerprint: 8E59 D6AA 445E FDB4 A153 3D5A 5F20 B3AE 0B5F 062F ]