[systemd-devel] [PATCH] shared: fix resource leak in config_parse_default_instance

Andreas Henriksson andreas at fatal.se
Tue Sep 16 12:36:26 PDT 2014


The recently allocated "printed" is not freed on error path.

Found by coverity. Fixes: CID#1237745
---
 src/shared/install.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/shared/install.c b/src/shared/install.c
index 5d3fcf5..61e572b 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -1025,8 +1025,10 @@ static int config_parse_default_instance(
         if (r < 0)
                 return r;
 
-        if (!unit_instance_is_valid(printed))
+        if (!unit_instance_is_valid(printed)) {
+                free(printed);
                 return -EINVAL;
+        }
 
         free(i->default_instance);
         i->default_instance = printed;
-- 
2.1.0



More information about the systemd-devel mailing list