From ba56672d0f0932384b3b749b48173f14ae9dc6fc Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 28 Dec 2005 21:19:58 +0000 Subject: make sure we handle the (malloc(0)==NULL) case as Aubrey points out via the e-mail list --- libc/sysdeps/linux/common/getgroups.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'libc/sysdeps/linux/common/getgroups.c') diff --git a/libc/sysdeps/linux/common/getgroups.c b/libc/sysdeps/linux/common/getgroups.c index 92cdca2d0..83d92627e 100644 --- a/libc/sysdeps/linux/common/getgroups.c +++ b/libc/sysdeps/linux/common/getgroups.c @@ -32,7 +32,7 @@ ret_error: size = MIN(size, sysconf(_SC_NGROUPS_MAX)); kernel_groups = (__kernel_gid_t *)malloc(sizeof(*kernel_groups) * size); - if (kernel_groups == NULL) + if (size && kernel_groups == NULL) goto ret_error; ngids = __syscall_getgroups(size, kernel_groups); @@ -41,7 +41,9 @@ ret_error: groups[i] = kernel_groups[i]; } } - free(kernel_groups); + + if (kernel_groups) + free(kernel_groups); return ngids; } } -- cgit v1.2.3