diff options
Diffstat (limited to 'nscd/netgroupcache.c')
-rw-r--r-- | nscd/netgroupcache.c | 37 |
1 files changed, 6 insertions, 31 deletions
diff --git a/nscd/netgroupcache.c b/nscd/netgroupcache.c index 9fc16640ae..58234b1492 100644 --- a/nscd/netgroupcache.c +++ b/nscd/netgroupcache.c @@ -141,7 +141,6 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req, size_t buffilled = sizeof (*dataset); char *buffer = NULL; size_t nentries = 0; - bool use_malloc = false; size_t group_len = strlen (key) + 1; union { @@ -159,7 +158,7 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req, } memset (&data, '\0', sizeof (data)); - buffer = alloca (buflen); + buffer = xmalloc (buflen); first_needed.elem.next = &first_needed.elem; memcpy (first_needed.elem.name, key, group_len); data.needed_groups = &first_needed.elem; @@ -241,21 +240,8 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req, if (buflen - req->key_len - bufused < needed) { - size_t newsize = MAX (2 * buflen, - buflen + 2 * needed); - if (use_malloc || newsize > 1024 * 1024) - { - buflen = newsize; - char *newbuf = xrealloc (use_malloc - ? buffer - : NULL, - buflen); - - buffer = newbuf; - use_malloc = true; - } - else - extend_alloca (buffer, buflen, newsize); + buflen += MAX (buflen, 2 * needed); + buffer = xrealloc (buffer, buflen); } nhost = memcpy (buffer + bufused, @@ -322,18 +308,8 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req, } else if (status == NSS_STATUS_UNAVAIL && e == ERANGE) { - size_t newsize = 2 * buflen; - if (use_malloc || newsize > 1024 * 1024) - { - buflen = newsize; - char *newbuf = xrealloc (use_malloc - ? buffer : NULL, buflen); - - buffer = newbuf; - use_malloc = true; - } - else - extend_alloca (buffer, buflen, newsize); + buflen *= 2; + buffer = xrealloc (buffer, buflen); } } @@ -478,8 +454,7 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req, } out: - if (use_malloc) - free (buffer); + free (buffer); *resultp = dataset; |