aboutsummaryrefslogtreecommitdiffstats
path: root/lib/env.c
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2023-03-09 13:10:41 +0100
committerKarel Zak <kzak@redhat.com>2023-03-09 13:10:41 +0100
commit11208370c90f44201ca7fbfaf01b76502034d544 (patch)
tree9a9c08d0643539b8c21523cf690512f05add66eb /lib/env.c
parent92168e2c0d669e4b16340964ff726b06a581306c (diff)
downloadutil-linux-11208370c90f44201ca7fbfaf01b76502034d544.tar.gz
lib/env: fix memory leak [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib/env.c')
-rw-r--r--lib/env.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/env.c b/lib/env.c
index 5c385f934b..2ccabff6fc 100644
--- a/lib/env.c
+++ b/lib/env.c
@@ -89,19 +89,22 @@ static struct ul_env_list *env_list_add(struct ul_env_list *ls0, const char *str
*/
struct ul_env_list *env_from_fd(int fd)
{
- char *buf = NULL;
+ char *buf = NULL, *p;
size_t rc = 0;
struct ul_env_list *ls = NULL;
if ((rc = read_all_alloc(fd, &buf)) < 1)
return NULL;
buf[rc] = '\0';
+ p = buf;
while (rc > 0) {
- ls = env_list_add(ls, buf);
- buf += strlen(buf) + 1;
- rc -= strlen(buf) + 1;
+ ls = env_list_add(ls, p);
+ p += strlen(p) + 1;
+ rc -= strlen(p) + 1;
}
+
+ free(buf);
return ls;
}