Skip to contentSkip to conversation

fsdev: Fix potential memory leak

PATCH Applied Stefan Weil 4 participants 6 messages Jun 16, 2013 – Jul 10, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fsdev: Fix potential memory leak

This leak was reported by cppcheck.

---
 fsdev/qemu-fsdev.c |    2 ++
 1 file changed, 2 insertions(+)
fsdev/qemu-fsdev.c +2 -0
index 6eaf36d..ccfec13 100644
@@ -76,6 +76,8 @@ int qemu_fsdev_add(QemuOpts *opts)
 
     if (fsle->fse.ops->parse_opts) {
         if (fsle->fse.ops->parse_opts(opts, &fsle->fse)) {
+            g_free(fsle->fse.fsdev_id);
+            g_free(fsle);
             return -1;
         }
     }
Signature · 1 line
1.7.10.4
#1 lore raw

Am 16.06.2013 12:02, schrieb Stefan Weil:

Quoted 12 lines

This leak was reported by cppcheck.

---
 fsdev/qemu-fsdev.c |    2 ++
 1 file changed, 2 insertions(+)
fsdev/qemu-fsdev.c +0 -0
index 6eaf36d..ccfec13 100644

fsdev/qemu-fsdev.c int qemu_fsdev_add(QemuOpts *opts) · line 83

Quoted 8 lines
fsdev/qemu-fsdev.c +2 -0
@@ -76,6 +76,8 @@ int qemu_fsdev_add(QemuOpts *opts)
 
     if (fsle->fse.ops->parse_opts) {
         if (fsle->fse.ops->parse_opts(opts, &fsle->fse)) {
+            g_free(fsle->fse.fsdev_id);
+            g_free(fsle);
             return -1;
         }
     }

Ping?

#2 lore raw
Quoted 14 lines · Stefan Weil

Am 16.06.2013 12:02, schrieb Stefan Weil:

Quoted 13 lines

This leak was reported by cppcheck.

---
 fsdev/qemu-fsdev.c |    2 ++
 1 file changed, 2 insertions(+)
fsdev/qemu-fsdev.c +0 -0
index 6eaf36d..ccfec13 100644
@@ -76,6 +76,8 @@ int qemu_fsdev_add(QemuOpts *opts)
 
Quoted 9 lines

fsdev/qemu-fsdev.c int qemu_fsdev_add(QemuOpts *opts) · line 83

Quoted 7 lines
fsdev/qemu-fsdev.c +2 -0
     if (fsle->fse.ops->parse_opts) {
         if (fsle->fse.ops->parse_opts(opts, &fsle->fse)) {
+            g_free(fsle->fse.fsdev_id);
+            g_free(fsle);
             return -1;
         }
     }

Ping?

Both the error path result in Qemu terminating right ? Do we really care about free in those case ?

-aneesh

#3 lore raw

Am 07.07.2013 19:15, schrieb Aneesh Kumar K.V:

Quoted 24 lines
Quoted 14 lines · Stefan Weil

Am 16.06.2013 12:02, schrieb Stefan Weil:

Quoted 13 lines

This leak was reported by cppcheck.

---
 fsdev/qemu-fsdev.c |    2 ++
 1 file changed, 2 insertions(+)
fsdev/qemu-fsdev.c +0 -0
index 6eaf36d..ccfec13 100644
@@ -76,6 +76,8 @@ int qemu_fsdev_add(QemuOpts *opts)
 
Quoted 8 lines

fsdev/qemu-fsdev.c int qemu_fsdev_add(QemuOpts *opts) · line 83

Quoted 7 lines
fsdev/qemu-fsdev.c +2 -0
     if (fsle->fse.ops->parse_opts) {
         if (fsle->fse.ops->parse_opts(opts, &fsle->fse)) {
+            g_free(fsle->fse.fsdev_id);
+            g_free(fsle);
             return -1;
         }
     }

Ping?

Quoted 4 lines

Both the error path result in Qemu terminating right ? Do we really care about free in those case ?

-aneesh

Yes, we do, because it simplifies code reviews if there are as few as possible warnings from static code analysers.

It is also not immediately obvious that QEMU terminates in the code which was patched here. Reviewers have to grep and look in vl.c, too, to see this.

Therefore I'd appreciate if this and similar code could be fixed (with low priority here).

Regards
Stefan W.

Reviewed-by on v1 1/1
#4 lore raw
In reply to Stefan Weil
Quoted 3 lines · Stefan Weil

This leak was reported by cppcheck.

Quoted 19 lines
---
 fsdev/qemu-fsdev.c |    2 ++
 1 file changed, 2 insertions(+)
fsdev/qemu-fsdev.c +2 -0
index 6eaf36d..ccfec13 100644
@@ -76,6 +76,8 @@ int qemu_fsdev_add(QemuOpts *opts)
 
     if (fsle->fse.ops->parse_opts) {
         if (fsle->fse.ops->parse_opts(opts, &fsle->fse)) {
+            g_free(fsle->fse.fsdev_id);
+            g_free(fsle);
             return -1;
         }
     }
Signature · 1 line
1.7.10.4