Review of changes for getnetgrent.c
Guy Helmer
ghelmer at palisadesys.com
Mon May 21 19:02:50 UTC 2012
On May 18, 2012, at 6:09 PM, Xin Li wrote:
> -----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);
> %%%
Like this?
if (len > 0) {
grp->ng_str[strpos] = (char *)
malloc(len + 1);
+ if (grp->ng_str[strpos] == NULL) {
+ int freepos;
+ for (freepos = 0; freepos < strpos; freepos++)
+ free(grp->ng_str[freepos]);
+ free(grp);
+ return(1);
+ }
bcopy(spos, grp->ng_str[strpos],
len + 1);
}
>
> There are a few return without space between the keyword and return value.
Do you recommend I fix all those instances in the file, or just the instances in this patch?
Thanks,
Guy
--------
This message has been scanned by ComplianceSafe, powered by Palisade's PacketSure.
More information about the freebsd-hackers
mailing list