[systemd-devel] [PATCH 2/2] detect-virt: dmi: fix mem leak

Andrew Jones drjones at redhat.com
Tue Nov 3 13:04:55 PST 2015


The variable 's' is still in scope until we exit the function. We
can't call read_one_line_file on it multiple times without calling
free in between.
---
 src/basic/virt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/basic/virt.c b/src/basic/virt.c
index 1e10fc755f201..f88bd04bd72ed 100644
--- a/src/basic/virt.c
+++ b/src/basic/virt.c
@@ -176,9 +176,10 @@ static int detect_vm_dmi(void) {
 
                 r = read_one_line_file(dmi_vendors[i], &s);
                 if (r < 0) {
-                        if (r == -ENOENT)
+                        if (r == -ENOENT) {
+                                free(s);
                                 continue;
-
+                        }
                         return r;
                 }
 
-- 
2.4.3



More information about the systemd-devel mailing list