1 --- glibc-2.12-2-gc4ccff1/nscd/grpcache.c.lrgrpissue 2002-03-19 01:06:04.905969517 +0530
2 +++ glibc-2.12-2-gc4ccff1/nscd/grpcache.c 2002-03-19 01:09:46.495970850 +0530
3 @@ -207,10 +207,11 @@ cache_addgr (struct database_dyn *db, in
4 change. Allocate memory on the cache since it is likely
5 discarded anyway. If it turns out to be necessary to have a
6 new record we can still allocate real memory. */
7 - bool dataset_in_stack_or_freed = false;
8 + bool dataset_temporary = false;
9 + bool dataset_malloced = false;
12 - if (he == NULL || ! __libc_use_alloca (alloca_used + total + n))
14 dataset = (struct dataset *) mempool_alloc (db, total + n, 1);
17 @@ -218,10 +219,16 @@ cache_addgr (struct database_dyn *db, in
18 /* We cannot permanently add the result in the moment. But
19 we can provide the result as is. Store the data in some
21 - dataset = (struct dataset *) alloca_account (total + n, alloca_used);
23 + if (! __libc_use_alloca (alloca_used + total + n))
25 + /* XXX What to do if malloc fails? */
26 + dataset = (struct dataset *) malloc (total + n);
27 + dataset_malloced = true;
30 + dataset = (struct dataset *) alloca_account (total + n, alloca_used);
31 /* We cannot add this record to the permanent database. */
32 - dataset_in_stack_or_freed = true;
33 + dataset_temporary = true;
36 dataset->head.allocsize = total + n;
37 @@ -276,13 +283,10 @@ cache_addgr (struct database_dyn *db, in
38 dh->timeout = dataset->head.timeout;
41 - /* If the new record was not allocated on the stack, then it must
42 - be freed. Note that it can no longer be used. */
43 - if (! dataset_in_stack_or_freed)
46 - dataset_in_stack_or_freed = true;
48 + /* If the new record was allocated via malloc, then we
49 + must free it here. */
50 + if (dataset_malloced)
55 @@ -298,7 +302,7 @@ cache_addgr (struct database_dyn *db, in
56 key_copy = (char *) newp + (key_copy - (char *) dataset);
58 dataset = memcpy (newp, dataset, total + n);
59 - dataset_in_stack_or_freed = false;
60 + dataset_temporary = false;
63 /* Mark the old record as obsolete. */
64 @@ -313,7 +317,7 @@ cache_addgr (struct database_dyn *db, in
68 - if (__builtin_expect (db->mmap_used, 1) && !dataset_in_stack_or_freed)
69 + if (__builtin_expect (db->mmap_used, 1) && ! dataset_temporary)
71 assert (db->wr_fd != -1);
72 assert ((char *) &dataset->resp > (char *) db->data);
73 @@ -340,7 +344,7 @@ cache_addgr (struct database_dyn *db, in
75 /* Add the record to the database. But only if it has not been
76 stored on the stack. */
77 - if (! dataset_in_stack_or_freed)
78 + if (! dataset_temporary)
80 /* If necessary, we also propagate the data to disk. */