summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2013-03-27 16:08:47 +0100
committerKarel Zak2013-03-27 16:08:47 +0100
commit8362545b4a3dc1b2903b7aa2e40eaf472aec130c (patch)
tree72c94c0b0005a03e0ff6e9fa1e7211b2e6ffb776
parentlibblkid: (udf) fix possible null pointer dereference [coverity scan] (diff)
downloadkernel-qcow2-util-linux-8362545b4a3dc1b2903b7aa2e40eaf472aec130c.tar.gz
kernel-qcow2-util-linux-8362545b4a3dc1b2903b7aa2e40eaf472aec130c.tar.xz
kernel-qcow2-util-linux-8362545b4a3dc1b2903b7aa2e40eaf472aec130c.zip
lib/xalloc: fix mamory leak in xgethostname() [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--include/xalloc.h6
-rw-r--r--term-utils/agetty.c10
2 files changed, 10 insertions, 6 deletions
diff --git a/include/xalloc.h b/include/xalloc.h
index 7b685e718..1f29621ef 100644
--- a/include/xalloc.h
+++ b/include/xalloc.h
@@ -83,9 +83,11 @@ static inline char *xgethostname(void)
size_t sz = get_hostname_max() + 1;
name = xmalloc(sizeof(char) * sz);
- if (gethostname(name, sz) != 0)
- return NULL;
+ if (gethostname(name, sz) != 0) {
+ free(name);
+ return NULL;
+ }
name[sz - 1] = '\0';
return name;
}
diff --git a/term-utils/agetty.c b/term-utils/agetty.c
index 7ac12f201..f745e6800 100644
--- a/term-utils/agetty.c
+++ b/term-utils/agetty.c
@@ -1209,9 +1209,10 @@ static char *xgethostname(void)
if (!name)
log_err(_("failed to allocate memory: %m"));
- if (gethostname(name, sz) != 0)
+ if (gethostname(name, sz) != 0) {
+ free(name);
return NULL;
-
+ }
name[sz - 1] = '\0';
return name;
}
@@ -1226,9 +1227,10 @@ static char *xgetdomainname(void)
if (!name)
log_err(_("failed to allocate memory: %m"));
- if (getdomainname(name, sz) != 0)
+ if (getdomainname(name, sz) != 0) {
+ free(name);
return NULL;
-
+ }
name[sz - 1] = '\0';
return name;
#endif