From 66c9dfdddcae35dfcae8a80faa6006bd29fb0027 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 31 May 2018 13:16:47 +0900 Subject: [PATCH 1/3] portable: fix memleak Fixes CID#1391382. --- src/portable/portablectl.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/portable/portablectl.c b/src/portable/portablectl.c index 39f273f21d..200435caae 100644 --- a/src/portable/portablectl.c +++ b/src/portable/portablectl.c @@ -111,7 +111,7 @@ static int extract_prefix(const char *path, char **ret) { } static int determine_matches(const char *image, char **l, bool allow_any, char ***ret) { - char **k; + _cleanup_strv_free_ char **k = NULL; int r; /* Determine the matches to apply. If the list is empty we derive the match from the image name. If the list @@ -128,7 +128,6 @@ static int determine_matches(const char *image, char **l, bool allow_any, char * if (!arg_quiet) log_info("(Matching unit files with prefix '%s'.)", prefix); - k = NULL; r = strv_consume(&k, prefix); if (r < 0) return log_oom(); @@ -142,7 +141,6 @@ static int determine_matches(const char *image, char **l, bool allow_any, char * if (!arg_quiet) log_info("(Matching all unit files.)"); - k = NULL; } else { _cleanup_free_ char *joined = NULL; @@ -158,7 +156,7 @@ static int determine_matches(const char *image, char **l, bool allow_any, char * log_info("(Matching unit files with prefixes '%s'.)", joined); } - *ret = k; + *ret = TAKE_PTR(k); return 0; } From 3c381a671f94e1cb3f17480f05e6038de3e81587 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 31 May 2018 13:26:24 +0900 Subject: [PATCH 2/3] load-fragment: add missing oom check Fixes CID#1391379. --- src/core/load-fragment.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 0bc162ad1d..bb258c4d29 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -811,7 +811,8 @@ int config_parse_socket_bindtodevice( return 0; } - free_and_strdup(&s->bind_to_device, rvalue); + if (free_and_strdup(&s->bind_to_device, rvalue) < 0) + return log_oom(); return 0; } From 17ee3d72da717e5bd59a267bc49ae674dd661a26 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 31 May 2018 13:27:06 +0900 Subject: [PATCH 3/3] load-fragment: use free_and_replace() --- src/core/load-fragment.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index bb258c4d29..f16b0d182b 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -4594,8 +4594,7 @@ static int open_follow(char **filename, FILE **_f, Set *names, char **_final) { if (r < 0) return r; - free(*filename); - *filename = target; + free_and_replace(*filename, target); } f = fdopen(fd, "re");