This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] Properly cache the result from looking up the nss databaseconfig
- From: Andreas Schwab <schwab at suse dot de>
- To: libc-alpha at sourceware dot org
- Date: Thu, 24 Jan 2013 12:46:27 +0100
- Subject: [PATCH] Properly cache the result from looking up the nss databaseconfig
The last argument of __nss_database_lookup is supposed to be used as a
cache for the lookup result, but three callers do not properly make use
of it: they store it in a local variable instead of in the static one
that is defined for that purpose. __nss_database_lookup is expecting to
be called only once for each database; if there is no config for a
database it reparses the default each time which allocates new memory
(though technically it's not a leak since it frees all of it at program
exit).
Andreas.
[BZ #15048]
* nscd/aicache.c (addhstaiX): Properly use the cache variable for
the nss database lookup.
* nscd/initgrcache.c (addinitgroupsX): Likewise.
* sysdeps/posix/getaddrinfo.c (gaih_inet): Likewise.
diff --git a/NEWS b/NEWS
index 9a039d8..08b3cb4 100644
--- a/NEWS
+++ b/NEWS
@@ -10,7 +10,7 @@ Version 2.18
* The following bugs are resolved with this release:
13951, 14200, 14317, 14327, 14496, 14964, 14981, 14982, 14985, 14994,
- 14996, 15003, 15020, 15023, 15036.
+ 14996, 15003, 15020, 15023, 15036, 15048.
Version 2.17
diff --git a/nscd/aicache.c b/nscd/aicache.c
index 23dcf80..17e06e7 100644
--- a/nscd/aicache.c
+++ b/nscd/aicache.c
@@ -85,20 +85,19 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
}
static service_user *hosts_database;
- service_user *nip = NULL;
+ service_user *nip;
int no_more;
int rc6 = 0;
int rc4 = 0;
int herrno = 0;
- if (hosts_database != NULL)
- {
- nip = hosts_database;
- no_more = 0;
- }
- else
+ if (hosts_database == NULL)
no_more = __nss_database_lookup ("hosts", NULL,
- "dns [!UNAVAIL=return] files", &nip);
+ "dns [!UNAVAIL=return] files",
+ &hosts_database);
+ else
+ no_more = 0;
+ nip = hosts_database;
if (__res_maybe_init (&_res, 0) == -1)
no_more = 1;
diff --git a/nscd/initgrcache.c b/nscd/initgrcache.c
index 196407c8..3981099 100644
--- a/nscd/initgrcache.c
+++ b/nscd/initgrcache.c
@@ -80,17 +80,16 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req,
}
static service_user *group_database;
- service_user *nip = NULL;
+ service_user *nip;
int no_more;
- if (group_database != NULL)
- {
- nip = group_database;
- no_more = 0;
- }
- else
+ if (group_database == NULL)
no_more = __nss_database_lookup ("group", NULL,
- "compat [NOTFOUND=return] files", &nip);
+ "compat [NOTFOUND=return] files",
+ &group_database);
+ else
+ no_more = 0;
+ nip = group_database;
/* We always use sysconf even if NGROUPS_MAX is defined. That way, the
limit can be raised in the kernel configuration without having to
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index d95c2d1..417489b 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -557,7 +557,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
struct gaih_addrtuple **pat = &at;
int no_data = 0;
int no_inet6_data = 0;
- service_user *nip = NULL;
+ service_user *nip;
enum nss_status inet6_status = NSS_STATUS_UNAVAIL;
enum nss_status status = NSS_STATUS_UNAVAIL;
int no_more;
@@ -790,15 +790,13 @@ gaih_inet (const char *name, const struct gaih_service *service,
}
#endif
- if (__nss_hosts_database != NULL)
- {
- no_more = 0;
- nip = __nss_hosts_database;
- }
- else
+ if (__nss_hosts_database == NULL)
no_more = __nss_database_lookup ("hosts", NULL,
"dns [!UNAVAIL=return] files",
- &nip);
+ &__nss_hosts_database);
+ else
+ no_more = 0;
+ nip = __nss_hosts_database;
/* Initialize configurations. */
if (__builtin_expect (!_res_hconf.initialized, 0))
--
1.8.1
--
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."