2019-05-08 13:47:45

by Steve Dickson

[permalink] [raw]
Subject: [PATCH 11/19] Removed resource leaks from systemd/rpc-pipefs-generator.c

systemd/rpc-pipefs-generator.c:73: leaked_storage: Variable "pipefs_unit"
going out of scope leaks the storage it points to
systemd/rpc-pipefs-generator.c:77: leaked_storage: Variable "pipefs_unit"
going out of scope leaks the storage it points to.
systemd/rpc-pipefs-generator.c:85: leaked_storage: Variable "pipefs_unit"
going out of scope leaks the storage it points to.
systemd/rpc-pipefs-generator.c:94: leaked_storage: Variable "pipefs_unit"
going out of scope leaks the storage it points to.

Signed-off-by: Steve Dickson <[email protected]>
---
systemd/rpc-pipefs-generator.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/systemd/rpc-pipefs-generator.c b/systemd/rpc-pipefs-generator.c
index 0b5da11..8e218aa 100644
--- a/systemd/rpc-pipefs-generator.c
+++ b/systemd/rpc-pipefs-generator.c
@@ -69,12 +69,16 @@ int generate_target(char *pipefs_path, const char *dirname)
return 1;

ret = generate_mount_unit(pipefs_path, pipefs_unit, dirname);
- if (ret)
+ if (ret) {
+ free(pipefs_unit);
return ret;
+ }

path = malloc(strlen(dirname) + 1 + sizeof(filebase));
- if (!path)
+ if (!path) {
+ free(pipefs_unit);
return 2;
+ }
sprintf(path, "%s", dirname);
mkdir(path, 0755);
strcat(path, filebase);
@@ -82,6 +86,7 @@ int generate_target(char *pipefs_path, const char *dirname)
if (!f)
{
free(path);
+ free(pipefs_unit);
return 1;
}

@@ -90,6 +95,7 @@ int generate_target(char *pipefs_path, const char *dirname)
fprintf(f, "After=%s\n", pipefs_unit);
fclose(f);
free(path);
+ free(pipefs_unit);

return 0;
}
--
2.20.1