diff options
author | Ulrich Drepper <drepper@redhat.com> | 1998-09-14 23:40:58 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 1998-09-14 23:40:58 +0000 |
commit | 0ff0d59e19b1a7db39f6d4e897a8bde0583a7c47 (patch) | |
tree | 8a0a2025ccb410c74b562b64dbc1fd6750102f36 /nscd/pwdcache.c | |
parent | d3f8acb39b5b7f7390ac7e6c5d09648837683d5f (diff) | |
download | glibc-0ff0d59e19b1a7db39f6d4e897a8bde0583a7c47.tar.gz glibc-0ff0d59e19b1a7db39f6d4e897a8bde0583a7c47.tar.xz glibc-0ff0d59e19b1a7db39f6d4e897a8bde0583a7c47.zip |
* nscd/pwdcache.c (save_pwd): Rewrite to use only one malloc call. (free_pwd): Adjust for this change. * nscd/grpcache.c (save_grp): Rewrite to use only one malloc call. (free_grp): Adjust for this change.
1998-09-14 23:36 Ulrich Drepper <drepper@cygnus.com> * nscd/pwdcache.c (save_pwd): Rewrite to use only one malloc call. (free_pwd): Adjust for this change. * nscd/grpcache.c (save_grp): Rewrite to use only one malloc call. (free_grp): Adjust for this change.
Diffstat (limited to 'nscd/pwdcache.c')
-rw-r--r-- | nscd/pwdcache.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/nscd/pwdcache.c b/nscd/pwdcache.c index 9b7c0a040a..85b4fe9bde 100644 --- a/nscd/pwdcache.c +++ b/nscd/pwdcache.c @@ -132,15 +132,31 @@ static struct passwd * save_pwd (struct passwd *src) { struct passwd *dest; - - dest = calloc (1, sizeof (struct passwd)); - dest->pw_name = strdup (src->pw_name); - dest->pw_passwd = strdup (src->pw_passwd); + size_t name_len = strlen (src->pw_name) + 1; + size_t passwd_len = strlen (src->pw_gecos) + 1; + size_t gecos_len = strlen (src->pw_dir) + 1; + size_t dir_len = strlen (src->pw_dir) + 1; + size_t shell_len = strlen (src->pw_shell) + 1; + char *cp; + + dest = malloc (sizeof (struct passwd) + + name_len + passwd_len + gecos_len + dir_len + shell_len); + if (dest == NULL) + return NULL; + + cp = (char *) (dest + 1); + dest->pw_name = cp; + cp = mempcpy (cp, src->pw_name, name_len); + dest->pw_passwd = cp; + cp = mempcpy (cp, src->pw_passwd, passwd_len); dest->pw_uid = src->pw_uid; dest->pw_gid = src->pw_gid; - dest->pw_gecos = strdup (src->pw_gecos); - dest->pw_dir = strdup (src->pw_dir); - dest->pw_shell = strdup (src->pw_shell); + dest->pw_gecos = cp; + cp = mempcpy (cp, src->pw_gecos, gecos_len); + dest->pw_dir = cp; + cp = mempcpy (cp, src->pw_dir, dir_len); + dest->pw_shell = cp; + mempcpy (cp, src->pw_shell, shell_len); return dest; } @@ -148,11 +164,6 @@ save_pwd (struct passwd *src) static void free_pwd (struct passwd *src) { - free (src->pw_name); - free (src->pw_passwd); - free (src->pw_gecos); - free (src->pw_dir); - free (src->pw_shell); free (src); } |