|
|
b9ba6d |
diff -rcp a/nscd/grpcache.c b/nscd/grpcache.c
|
|
|
b9ba6d |
*** a/nscd/grpcache.c Wed Apr 11 12:50:07 2012
|
|
|
b9ba6d |
--- b/nscd/grpcache.c Wed Apr 11 21:45:58 2012
|
|
|
b9ba6d |
*************** cache_addgr (struct database_dyn *db, in
|
|
|
b9ba6d |
*** 178,184 ****
|
|
|
b9ba6d |
char *cp;
|
|
|
b9ba6d |
const size_t key_len = strlen (key);
|
|
|
b9ba6d |
const size_t buf_len = 3 * sizeof (grp->gr_gid) + key_len + 1;
|
|
|
b9ba6d |
! char *buf = alloca (buf_len);
|
|
|
b9ba6d |
ssize_t n;
|
|
|
b9ba6d |
size_t cnt;
|
|
|
b9ba6d |
|
|
|
b9ba6d |
--- 178,185 ----
|
|
|
b9ba6d |
char *cp;
|
|
|
b9ba6d |
const size_t key_len = strlen (key);
|
|
|
b9ba6d |
const size_t buf_len = 3 * sizeof (grp->gr_gid) + key_len + 1;
|
|
|
b9ba6d |
! size_t alloca_used = 0;
|
|
|
b9ba6d |
! char *buf = alloca_account (buf_len, alloca_used);
|
|
|
b9ba6d |
ssize_t n;
|
|
|
b9ba6d |
size_t cnt;
|
|
|
b9ba6d |
|
|
|
b9ba6d |
*************** cache_addgr (struct database_dyn *db, in
|
|
|
b9ba6d |
*** 190,196 ****
|
|
|
b9ba6d |
/* Determine the length of all members. */
|
|
|
b9ba6d |
while (grp->gr_mem[gr_mem_cnt])
|
|
|
b9ba6d |
++gr_mem_cnt;
|
|
|
b9ba6d |
! gr_mem_len = (uint32_t *) alloca (gr_mem_cnt * sizeof (uint32_t));
|
|
|
b9ba6d |
for (gr_mem_cnt = 0; grp->gr_mem[gr_mem_cnt]; ++gr_mem_cnt)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
gr_mem_len[gr_mem_cnt] = strlen (grp->gr_mem[gr_mem_cnt]) + 1;
|
|
|
b9ba6d |
--- 191,198 ----
|
|
|
b9ba6d |
/* Determine the length of all members. */
|
|
|
b9ba6d |
while (grp->gr_mem[gr_mem_cnt])
|
|
|
b9ba6d |
++gr_mem_cnt;
|
|
|
b9ba6d |
! gr_mem_len = (uint32_t *) alloca_account (gr_mem_cnt * sizeof (uint32_t),
|
|
|
b9ba6d |
! alloca_used);
|
|
|
b9ba6d |
for (gr_mem_cnt = 0; grp->gr_mem[gr_mem_cnt]; ++gr_mem_cnt)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
gr_mem_len[gr_mem_cnt] = strlen (grp->gr_mem[gr_mem_cnt]) + 1;
|
|
|
b9ba6d |
*************** cache_addgr (struct database_dyn *db, in
|
|
|
b9ba6d |
*** 205,214 ****
|
|
|
b9ba6d |
change. Allocate memory on the cache since it is likely
|
|
|
b9ba6d |
discarded anyway. If it turns out to be necessary to have a
|
|
|
b9ba6d |
new record we can still allocate real memory. */
|
|
|
b9ba6d |
! bool alloca_used = false;
|
|
|
b9ba6d |
dataset = NULL;
|
|
|
b9ba6d |
|
|
|
b9ba6d |
! if (he == NULL)
|
|
|
b9ba6d |
dataset = (struct dataset *) mempool_alloc (db, total + n, 1);
|
|
|
b9ba6d |
|
|
|
b9ba6d |
if (dataset == NULL)
|
|
|
b9ba6d |
--- 207,216 ----
|
|
|
b9ba6d |
change. Allocate memory on the cache since it is likely
|
|
|
b9ba6d |
discarded anyway. If it turns out to be necessary to have a
|
|
|
b9ba6d |
new record we can still allocate real memory. */
|
|
|
b9ba6d |
! bool dataset_in_stack_or_freed = false;
|
|
|
b9ba6d |
dataset = NULL;
|
|
|
b9ba6d |
|
|
|
b9ba6d |
! if (he == NULL || ! __libc_use_alloca (alloca_used + total + n))
|
|
|
b9ba6d |
dataset = (struct dataset *) mempool_alloc (db, total + n, 1);
|
|
|
b9ba6d |
|
|
|
b9ba6d |
if (dataset == NULL)
|
|
|
b9ba6d |
*************** cache_addgr (struct database_dyn *db, in
|
|
|
b9ba6d |
*** 216,225 ****
|
|
|
b9ba6d |
/* We cannot permanently add the result in the moment. But
|
|
|
b9ba6d |
we can provide the result as is. Store the data in some
|
|
|
b9ba6d |
temporary memory. */
|
|
|
b9ba6d |
! dataset = (struct dataset *) alloca (total + n);
|
|
|
b9ba6d |
|
|
|
b9ba6d |
/* We cannot add this record to the permanent database. */
|
|
|
b9ba6d |
! alloca_used = true;
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
|
|
|
b9ba6d |
dataset->head.allocsize = total + n;
|
|
|
b9ba6d |
--- 218,227 ----
|
|
|
b9ba6d |
/* We cannot permanently add the result in the moment. But
|
|
|
b9ba6d |
we can provide the result as is. Store the data in some
|
|
|
b9ba6d |
temporary memory. */
|
|
|
b9ba6d |
! dataset = (struct dataset *) alloca_account (total + n, alloca_used);
|
|
|
b9ba6d |
|
|
|
b9ba6d |
/* We cannot add this record to the permanent database. */
|
|
|
b9ba6d |
! dataset_in_stack_or_freed = true;
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
|
|
|
b9ba6d |
dataset->head.allocsize = total + n;
|
|
|
b9ba6d |
*************** cache_addgr (struct database_dyn *db, in
|
|
|
b9ba6d |
*** 273,278 ****
|
|
|
b9ba6d |
--- 275,288 ----
|
|
|
b9ba6d |
allocated on the stack and need not be freed. */
|
|
|
b9ba6d |
dh->timeout = dataset->head.timeout;
|
|
|
b9ba6d |
++dh->nreloads;
|
|
|
b9ba6d |
+
|
|
|
b9ba6d |
+ /* If the new record was not allocated on the stack, then it must
|
|
|
b9ba6d |
+ be freed. Note that it can no longer be used. */
|
|
|
b9ba6d |
+ if (! dataset_in_stack_or_freed)
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ free (dataset);
|
|
|
b9ba6d |
+ dataset_in_stack_or_freed = true;
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
else
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
*************** cache_addgr (struct database_dyn *db, in
|
|
|
b9ba6d |
*** 288,294 ****
|
|
|
b9ba6d |
key_copy = (char *) newp + (key_copy - (char *) dataset);
|
|
|
b9ba6d |
|
|
|
b9ba6d |
dataset = memcpy (newp, dataset, total + n);
|
|
|
b9ba6d |
! alloca_used = false;
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
|
|
|
b9ba6d |
/* Mark the old record as obsolete. */
|
|
|
b9ba6d |
--- 298,304 ----
|
|
|
b9ba6d |
key_copy = (char *) newp + (key_copy - (char *) dataset);
|
|
|
b9ba6d |
|
|
|
b9ba6d |
dataset = memcpy (newp, dataset, total + n);
|
|
|
b9ba6d |
! dataset_in_stack_or_freed = false;
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
|
|
|
b9ba6d |
/* Mark the old record as obsolete. */
|
|
|
b9ba6d |
*************** cache_addgr (struct database_dyn *db, in
|
|
|
b9ba6d |
*** 303,309 ****
|
|
|
b9ba6d |
assert (fd != -1);
|
|
|
b9ba6d |
|
|
|
b9ba6d |
#ifdef HAVE_SENDFILE
|
|
|
b9ba6d |
! if (__builtin_expect (db->mmap_used, 1) && !alloca_used)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
assert (db->wr_fd != -1);
|
|
|
b9ba6d |
assert ((char *) &dataset->resp > (char *) db->data);
|
|
|
b9ba6d |
--- 313,319 ----
|
|
|
b9ba6d |
assert (fd != -1);
|
|
|
b9ba6d |
|
|
|
b9ba6d |
#ifdef HAVE_SENDFILE
|
|
|
b9ba6d |
! if (__builtin_expect (db->mmap_used, 1) && !dataset_in_stack_or_freed)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
assert (db->wr_fd != -1);
|
|
|
b9ba6d |
assert ((char *) &dataset->resp > (char *) db->data);
|
|
|
b9ba6d |
*************** cache_addgr (struct database_dyn *db, in
|
|
|
b9ba6d |
*** 330,336 ****
|
|
|
b9ba6d |
|
|
|
b9ba6d |
/* Add the record to the database. But only if it has not been
|
|
|
b9ba6d |
stored on the stack. */
|
|
|
b9ba6d |
! if (! alloca_used)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
/* If necessary, we also propagate the data to disk. */
|
|
|
b9ba6d |
if (db->persistent)
|
|
|
b9ba6d |
--- 340,346 ----
|
|
|
b9ba6d |
|
|
|
b9ba6d |
/* Add the record to the database. But only if it has not been
|
|
|
b9ba6d |
stored on the stack. */
|
|
|
b9ba6d |
! if (! dataset_in_stack_or_freed)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
/* If necessary, we also propagate the data to disk. */
|
|
|
b9ba6d |
if (db->persistent)
|