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:
committed by
Zbigniew Jędrzejewski-Szmek
parent
b37e4d9c87
commit
9a61e8fca2
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user