Skip to contentSkip to conversation

libqtest: only call fclose() on open files

PATCH Applied Jesse Larrew 2 participants 3 messages Apr 29, 2013 – May 2, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libqtest: only call fclose() on open files

libqtest.c can segfault when calling fclose() if the pidfile wasn't opened successfully. This patch fixes the issue.

---
 tests/libqtest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/libqtest.c +1 -1
index 884f959..879ffe9 100644
@@ -99,8 +99,8 @@ static pid_t qtest_qemu_pid(QTestState *s)
         if (fgets(buffer, sizeof(buffer), f)) {
             pid = atoi(buffer);
         }
+        fclose(f);
     }
-    fclose(f);
     return pid;
 }
 
Signature · 1 line
1.7.11.7
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Jesse Larrew

libqtest.c can segfault when calling fclose() if the pidfile wasn't opened successfully. This patch fixes the issue.

Regards,

Anthony Liguori

Quoted 20 lines
---
 tests/libqtest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/libqtest.c +1 -1
index 884f959..879ffe9 100644
@@ -99,8 +99,8 @@ static pid_t qtest_qemu_pid(QTestState *s)
         if (fgets(buffer, sizeof(buffer), f)) {
             pid = atoi(buffer);
         }
+        fclose(f);
     }
-    fclose(f);
     return pid;
 }
 
Signature · 1 line
1.7.11.7