Re: [lc-devel] [OLPC-devel] Announce: Compressed cache 'pre-alpha-001' release :)
Status: Beta
Brought to you by:
nitin_sf
From: Arnd B. <ar...@ar...> - 2006-07-27 11:53:54
|
On Thursday 27 July 2006 09:29, Nitin Gupta wrote: > some_func() > { > =A0 =A0 void *a, *b; > =A0 =A0 a =3D alloc() > =A0 =A0 if (!a) goto out: > =A0 =A0 b =3D alloc(); > =A0 =A0 ... > out: > =A0 =A0 if (a) free(a) > =A0 =A0 if (b) free(b) > =A0 =A0 ... > } >=20 > Here you (correctly) get 'possible uninitialized usage for b' warning.=20 > That's why I initialize those local variables. Well, I'd prefer to write this as=20 some_func() { void *a, *b; int ret; ret =3D -ENOMEM; a =3D alloc(); if (!a) goto out_a; b =3D alloc(); if (!b) goto out_b; ... ret =3D 0; free(b); =20 out_b: free(a); out_a: return ret; } Note: - statement after if() on following line - no variables initialized on declaration (ret could be) - only clean up what you created. - kfree(NULL); is ok Arnd <>< |