unit-name: fix a potential memory leak

Also, add a test which verifies the issue is indeed gone.

Fixes: CID#1429014
Followup to: ab19db01ae
This commit is contained in:
Frantisek Sumsal
2020-07-06 17:13:37 +02:00
committed by Zbigniew Jędrzejewski-Szmek
parent b37e4d9c87
commit 9a61e8fca2
2 changed files with 4 additions and 3 deletions
+2 -3
View File
@@ -537,8 +537,7 @@ int unit_name_from_path(const char *path, const char *suffix, char **ret) {
}
int unit_name_from_path_instance(const char *prefix, const char *path, const char *suffix, char **ret) {
_cleanup_free_ char *p = NULL;
char *s;
_cleanup_free_ char *p = NULL, *s = NULL;
int r;
assert(prefix);
@@ -564,7 +563,7 @@ int unit_name_from_path_instance(const char *prefix, const char *path, const cha
if (!unit_name_is_valid(s, UNIT_NAME_INSTANCE))
return -EINVAL;
*ret = s;
*ret = TAKE_PTR(s);
return 0;
}