From fa9ac567a7f1593c586cca57362f6b542985e5d7 Mon Sep 17 00:00:00 2001 From: Serge Hallyn Date: Tue, 21 May 2013 20:31:04 -0500 Subject: [PATCH] attach: and cgroup.c: be overly cautious Realistically (as Dwight points out) it doesn't seem possible that getline won't return at least one line in this functions, however just to make absolutely sure we don't get a segv on free(NULL), check line != NULL before freeing it on exit. Signed-off-by: Serge Hallyn --- src/lxc/attach.c | 3 ++- src/lxc/cgroup.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lxc/attach.c b/src/lxc/attach.c index d8b4915d5..a33d24f89 100644 --- a/src/lxc/attach.c +++ b/src/lxc/attach.c @@ -114,7 +114,8 @@ struct lxc_proc_context_info *lxc_proc_get_context_info(pid_t pid) } } - free(line); + if (line) + free(line); fclose(proc_file); if (!found) { diff --git a/src/lxc/cgroup.c b/src/lxc/cgroup.c index 2ffbb54b5..bb1268b30 100644 --- a/src/lxc/cgroup.c +++ b/src/lxc/cgroup.c @@ -503,7 +503,8 @@ static char *get_all_cgroups(void) } out: - free(line); + if (line) + free(line); fclose(f); return ret; }