2009-09-07 Steve Grubb <sgrubb@redhat.com>
* libmisc/copydir.c, lib/shadowmem.c, lib/groupmem.c, lib/pwmem.c: Fix some memory leaks.
This commit is contained in:
parent
8806b07bd2
commit
1e6b107d99
@ -1,3 +1,8 @@
|
|||||||
|
2009-09-07 Steve Grubb <sgrubb@redhat.com>
|
||||||
|
|
||||||
|
* libmisc/copydir.c, lib/shadowmem.c, lib/groupmem.c, lib/pwmem.c:
|
||||||
|
Fix some memory leaks.
|
||||||
|
|
||||||
2009-09-06 Nicolas François <nicolas.francois@centraliens.net>
|
2009-09-06 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
* src/userdel.c, src/lastlog.c, src/gpasswd.c, src/newusers.c,
|
* src/userdel.c, src/lastlog.c, src/gpasswd.c, src/newusers.c,
|
||||||
|
@ -51,10 +51,13 @@
|
|||||||
*gr = *grent;
|
*gr = *grent;
|
||||||
gr->gr_name = strdup (grent->gr_name);
|
gr->gr_name = strdup (grent->gr_name);
|
||||||
if (NULL == gr->gr_name) {
|
if (NULL == gr->gr_name) {
|
||||||
|
free(gr);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
gr->gr_passwd = strdup (grent->gr_passwd);
|
gr->gr_passwd = strdup (grent->gr_passwd);
|
||||||
if (NULL == gr->gr_passwd) {
|
if (NULL == gr->gr_passwd) {
|
||||||
|
free(gr->gr_name);
|
||||||
|
free(gr);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,11 +65,21 @@
|
|||||||
|
|
||||||
gr->gr_mem = (char **) malloc ((i + 1) * sizeof (char *));
|
gr->gr_mem = (char **) malloc ((i + 1) * sizeof (char *));
|
||||||
if (NULL == gr->gr_mem) {
|
if (NULL == gr->gr_mem) {
|
||||||
|
free(gr->gr_passwd);
|
||||||
|
free(gr->gr_name);
|
||||||
|
free(gr);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
for (i = 0; grent->gr_mem[i]; i++) {
|
for (i = 0; grent->gr_mem[i]; i++) {
|
||||||
gr->gr_mem[i] = strdup (grent->gr_mem[i]);
|
gr->gr_mem[i] = strdup (grent->gr_mem[i]);
|
||||||
if (NULL == gr->gr_mem[i]) {
|
if (NULL == gr->gr_mem[i]) {
|
||||||
|
int j;
|
||||||
|
for (j=0; j<i; j++)
|
||||||
|
free(gr->gr_mem[j]);
|
||||||
|
free(gr->gr_mem);
|
||||||
|
free(gr->gr_passwd);
|
||||||
|
free(gr->gr_name);
|
||||||
|
free(gr);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
lib/pwmem.c
15
lib/pwmem.c
@ -51,22 +51,37 @@
|
|||||||
*pw = *pwent;
|
*pw = *pwent;
|
||||||
pw->pw_name = strdup (pwent->pw_name);
|
pw->pw_name = strdup (pwent->pw_name);
|
||||||
if (NULL == pw->pw_name) {
|
if (NULL == pw->pw_name) {
|
||||||
|
free(pw);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
pw->pw_passwd = strdup (pwent->pw_passwd);
|
pw->pw_passwd = strdup (pwent->pw_passwd);
|
||||||
if (NULL == pw->pw_passwd) {
|
if (NULL == pw->pw_passwd) {
|
||||||
|
free(pw->pw_name);
|
||||||
|
free(pw);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
pw->pw_gecos = strdup (pwent->pw_gecos);
|
pw->pw_gecos = strdup (pwent->pw_gecos);
|
||||||
if (NULL == pw->pw_gecos) {
|
if (NULL == pw->pw_gecos) {
|
||||||
|
free(pw->pw_passwd);
|
||||||
|
free(pw->pw_name);
|
||||||
|
free(pw);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
pw->pw_dir = strdup (pwent->pw_dir);
|
pw->pw_dir = strdup (pwent->pw_dir);
|
||||||
if (NULL == pw->pw_dir) {
|
if (NULL == pw->pw_dir) {
|
||||||
|
free(pw->pw_gecos);
|
||||||
|
free(pw->pw_passwd);
|
||||||
|
free(pw->pw_name);
|
||||||
|
free(pw);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
pw->pw_shell = strdup (pwent->pw_shell);
|
pw->pw_shell = strdup (pwent->pw_shell);
|
||||||
if (NULL == pw->pw_shell) {
|
if (NULL == pw->pw_shell) {
|
||||||
|
free(pw->pw_dir);
|
||||||
|
free(pw->pw_gecos);
|
||||||
|
free(pw->pw_passwd);
|
||||||
|
free(pw->pw_name);
|
||||||
|
free(pw);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,10 +52,13 @@
|
|||||||
*sp = *spent;
|
*sp = *spent;
|
||||||
sp->sp_namp = strdup (spent->sp_namp);
|
sp->sp_namp = strdup (spent->sp_namp);
|
||||||
if (NULL == sp->sp_namp) {
|
if (NULL == sp->sp_namp) {
|
||||||
|
free(sp);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
sp->sp_pwdp = strdup (spent->sp_pwdp);
|
sp->sp_pwdp = strdup (spent->sp_pwdp);
|
||||||
if (NULL == sp->sp_pwdp) {
|
if (NULL == sp->sp_pwdp) {
|
||||||
|
free(sp->sp_namp);
|
||||||
|
free(sp);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,6 +443,7 @@ static char *readlink_malloc (const char *filename)
|
|||||||
nchars = readlink (filename, buffer, size);
|
nchars = readlink (filename, buffer, size);
|
||||||
|
|
||||||
if (nchars < 0) {
|
if (nchars < 0) {
|
||||||
|
free(buffer);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user