Date: Fri, 18 May 2012 16:09:12 -0700 From: Xin Li <delphij@delphij.net> To: Guy Helmer <ghelmer@palisadesys.com> Cc: freebsd-hackers@freebsd.org, d@delphij.net Subject: Re: Review of changes for getnetgrent.c Message-ID: <4FB6D698.9030305@delphij.net> In-Reply-To: <4EE466CC-5F93-485C-8E1F-907F8049FD61@palisadesys.com> References: <4EE466CC-5F93-485C-8E1F-907F8049FD61@palisadesys.com>
index | next in thread | previous in thread | raw e-mail
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
On 05/18/12 14:58, Guy Helmer wrote:
> To close PR bin/83340, I have this change worked up to resolve
> memory allocation failure handling and avoid creating bad entries
> in the grp list due to memory allocation failures while building a
> new entry.
>
> Before committing, I wanted to run it past others to see if there
> were any problems with it.
%%%
@@ -477,6 +475,13 @@
if (len > 0) {
grp->ng_str[strpos] = (char *)
malloc(len + 1);
+ if (grp->ng_str[strpos] == NULL) {
+ for (freepos = 0; freepos < strpos; freepos++)
+ if (grp->ng_str[freepos] != NULL)
+ free(grp->ng_str[freepos]);
+ free(grp);
+ return(1);
+ }
bcopy(spos, grp->ng_str[strpos],
len + 1);
%%%
The if (grp->ng_str[freepos] != NULL) here seems to be unnecessary to
me because in most cases these are false, and free() does the test
regardless. Also, I think freepos can be declared within this scope
level.
There are a few return without space between the keyword and return value.
Other than these it looks fine to me. Thanks for working on this!
Cheers,
- --
Xin LI <delphij@delphij.net> https://www.delphij.net/
FreeBSD - The Power to Serve! Live free or die
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (FreeBSD)
iQEcBAEBCAAGBQJPttaYAAoJEG80Jeu8UPuzFEsH/i7JwIPdk15sP3E2/YpesYQu
veavnS6tebylFhniKukN4GRsS5mpbs9AmnxbNUBfF7InlzcnxOeUX9mHJepxbZQX
Bz8wgsvfxlrrseIyscdwm7b4XQK3dLv+VwpbQ4fqACOX1kGEQ/GsIc65JLyp2Gzo
fRLkHRAO5s3FVT5f11vsy2Ry16AmQhL2Sg9+mrGqeIbhppmDCgWfoF+rmD/7fn15
0OuJNn/S3Cz3zo+ZHI9OE1W8mkMox4kznQmv6vH/hM3Gk1cY9h66UybuBWsY31dI
WF5Y5WoJBuncFlDxGkaZv2jiRAqgkfWILVWKcjyejtGgVYPEWAjIgHLyyVk7H4g=
=ewU+
-----END PGP SIGNATURE-----
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4FB6D698.9030305>
