Re: [AD] fixes.. malloc()

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sunday 15 December 2002 00:26, aj wrote:
> /allegro417/src/readbmp.c  line55
>
> for (iter = bitmap_type_list; iter->next; iter = iter->next);
> iter = iter->next = malloc(sizeof(struct BITMAP_TYPE_INFO));
>
> shouldn't the for loop go to just iter, so it finds the NULL on the
> end of list.

No, because on the line after the for loop `iter' is dereferenced, so it 
can't be 0. The for loop stops one before the end (ie. `iter->next' is 
0 but `iter' isn't).

[snip - redundant 'free' checks]
You are right, these should be removed. I find it's best not to check 
before calling free() because you could write the check the wrong way 
around and end up not freeing valid pointers, but only 0 pointers!

Bye for now,
- -- 
Laurence Withers,  lwithers@xxxxxxxxxx
(GnuPG 04A646EA) http://www.lwithers.demon.co.uk/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE9/I1nUdhclgSmRuoRAlzVAKCdD3P4lfAgfPOIzCGnEdELMgRbCgCeK68k
crR0XdGuhErOgT14NQSquuo=
=3Fgk
-----END PGP SIGNATURE-----



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/