Skip to contentSkip to conversation

Pair g_malloc() with g_free(), not free()

PATCH Applied Markus Armbruster 4 participants 12 messages Jan 28, 2015 – Feb 7, 2015

lore
Share & tools
lore
#3 lore raw

PATCH 2/4 qemu-option: Pair g_malloc() with g_free(), not free()

In reply to Markus Armbruster

Spotted by Coverity with preview checker ALLOC_FREE_MISMATCH enabled and my "coverity: Model g_free() isn't necessarily free()" model patch applied.

---
 util/qemu-option.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
util/qemu-option.c +2 -2
index c779150..d3ab65d 100644
@@ -230,7 +230,7 @@ bool has_help_option(const char *param)
     }
 
 out:
-    free(buf);
+    g_free(buf);
     return result;
 }
 
@@ -255,7 +255,7 @@ bool is_valid_option_list(const char *param)
     }
 
 out:
-    free(buf);
+    g_free(buf);
     return result;
 }
 
Signature · 1 line
1.9.3
#5 lore raw

PATCH 3/4 spapr_vio: Pair g_malloc() with g_free(), not free()

In reply to Markus Armbruster

Spotted by Coverity with preview checker ALLOC_FREE_MISMATCH enabled and my "coverity: Model g_free() isn't necessarily free()" model patch applied.

---
 hw/ppc/spapr_vio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/spapr_vio.c +1 -1
index dc9e46a..032ee1a 100644
@@ -648,7 +648,7 @@ int spapr_populate_vdevice(VIOsPAPRBus *bus, void *fdt)
 
     ret = 0;
 out:
-    free(qdevs);
+    g_free(qdevs);
 
     return ret;
 }
Signature · 1 line
1.9.3
#0 lore raw

cover Pair g_malloc() with g_free(), not free()

I'm routing these patches through qemu-trivial, even though some of them touch actively maintained code, and could go through the respective tree instead:

* PATCH 3 sPAPR (Alex)

* PATCH 4 USB (Gerd)

If you want me to reroute any of them, let me know.

Markus Armbruster (4):
qemu-option: Replace pointless use of g_malloc0() by g_malloc()
qemu-option: Pair g_malloc() with g_free(), not free()
spapr_vio: Pair g_malloc() with g_free(), not free()
usb: Pair g_malloc() with g_free(), not free()

 hw/ppc/spapr_vio.c | 2 +-
 hw/usb/desc-msos.c | 2 +-
 util/qemu-option.c | 8 ++++----
 3 files changed, 6 insertions(+), 6 deletions(-)
Signature · 1 line
1.9.3
#1 lore raw

PATCH 1/4 qemu-option: Replace pointless use of g_malloc0() by g_malloc()

get_opt_value() takes a write-only buffer, so zeroing it is pointless. We don't do it elsewhere, either.

---
 util/qemu-option.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
util/qemu-option.c +2 -2
index a708241..c779150 100644
@@ -213,7 +213,7 @@ void parse_option_size(const char *name, const char *value,
 bool has_help_option(const char *param)
 {
     size_t buflen = strlen(param) + 1;
-    char *buf = g_malloc0(buflen);
+    char *buf = g_malloc(buflen);
     const char *p = param;
     bool result = false;
 
@@ -237,7 +237,7 @@ out:
 bool is_valid_option_list(const char *param)
 {
     size_t buflen = strlen(param) + 1;
-    char *buf = g_malloc0(buflen);
+    char *buf = g_malloc(buflen);
     const char *p = param;
     bool result = true;
 
Signature · 1 line
1.9.3
#7 lore raw

PATCH 4/4 usb: Pair g_malloc() with g_free(), not free()

In reply to Markus Armbruster

Spotted by Coverity with preview checker ALLOC_FREE_MISMATCH enabled and my "coverity: Model g_free() isn't necessarily free()" model patch applied.

---
 hw/usb/desc-msos.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/usb/desc-msos.c +1 -1
index 334d1ae..32c3600 100644
@@ -231,7 +231,7 @@ int usb_desc_msos(const USBDesc *desc,  USBPacket *p,
         length = len;
     }
     memcpy(dest, buf, length);
-    free(buf);
+    g_free(buf);
 
     p->actual_length = length;
     return 0;
Signature · 1 line
1.9.3
Reviewed-by on the v1 series
#9 lore raw
In reply to Markus Armbruster
Quoted 9 lines · Markus Armbruster

I'm routing these patches through qemu-trivial, even though some of them touch actively maintained code, and could go through the respective tree instead:

* PATCH 3 sPAPR (Alex)

* PATCH 4 USB (Gerd)

If you want me to reroute any of them, let me know.

[for patches like these, sometimes I like to use git format-patch -U20 or whatever it takes to make the patch show full context of the allocation a few lines earlier that matches with the actual g_free fix, so that reviewers don't have to open the file themselves. It makes for larger emails, but potentially faster reviews. But it's not the end of the world to stick with the default 3-line context]

Quoted 12 lines

Markus Armbruster (4):
qemu-option: Replace pointless use of g_malloc0() by g_malloc()
qemu-option: Pair g_malloc() with g_free(), not free()
spapr_vio: Pair g_malloc() with g_free(), not free()
usb: Pair g_malloc() with g_free(), not free()

 hw/ppc/spapr_vio.c | 2 +-
 hw/usb/desc-msos.c | 2 +-
 util/qemu-option.c | 8 ++++----
 3 files changed, 6 insertions(+), 6 deletions(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Reviewed-by on v1 2/4
#4 lore raw

Re: [Qemu-devel] [PATCH 2/4] qemu-option: Pair g_malloc() with g_free(), not free()

In reply to Markus Armbruster
Quoted 8 lines · Markus Armbruster

Spotted by Coverity with preview checker ALLOC_FREE_MISMATCH enabled and my "coverity: Model g_free() isn't necessarily free()" model patch applied.

---
 util/qemu-option.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by on v1 3/4
#6 lore raw

Re: [Qemu-devel] [PATCH 3/4] spapr_vio: Pair g_malloc() with g_free(), not free()

In reply to Markus Armbruster
Quoted 8 lines · Markus Armbruster

Spotted by Coverity with preview checker ALLOC_FREE_MISMATCH enabled and my "coverity: Model g_free() isn't necessarily free()" model patch applied.

---
 hw/ppc/spapr_vio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
#8 lore raw

Re: [Qemu-devel] [PATCH 4/4] usb: Pair g_malloc() with g_free(), not free()

In reply to Markus Armbruster
Quoted 14 lines · Markus Armbruster

Spotted by Coverity with preview checker ALLOC_FREE_MISMATCH enabled and my "coverity: Model g_free() isn't necessarily free()" model patch applied.

---
 hw/usb/desc-msos.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/usb/desc-msos.c +0 -0
index 334d1ae..32c3600 100644

hw/usb/desc-msos.c int usb_desc_msos(const USBDesc *desc, USBPacket *p, · line 237

Quoted 8 lines
hw/usb/desc-msos.c +1 -1
@@ -231,7 +231,7 @@ int usb_desc_msos(const USBDesc *desc,  USBPacket *p,
         length = len;
     }
     memcpy(dest, buf, length);
-    free(buf);
+    g_free(buf);
 
     p->actual_length = length;
     return 0;

This patch had been added Gerd's usb queue :)

http://lists.gnu.org/archive/html/qemu-devel/2015-01/msg01998.html

Regards,
-Gonglei

#10 lore raw
In reply to Markus Armbruster

Got reviews, want qemu-trivial: *ping* :)

Quoted 20 lines · Markus Armbruster

I'm routing these patches through qemu-trivial, even though some of them touch actively maintained code, and could go through the respective tree instead:

* PATCH 3 sPAPR (Alex)

* PATCH 4 USB (Gerd)

If you want me to reroute any of them, let me know.

Markus Armbruster (4):
qemu-option: Replace pointless use of g_malloc0() by g_malloc()
qemu-option: Pair g_malloc() with g_free(), not free()
spapr_vio: Pair g_malloc() with g_free(), not free()
usb: Pair g_malloc() with g_free(), not free()

 hw/ppc/spapr_vio.c | 2 +-
 hw/usb/desc-msos.c | 2 +-
 util/qemu-option.c | 8 ++++----
 3 files changed, 6 insertions(+), 6 deletions(-)
#11 lore raw
In reply to Markus Armbruster
Quoted 5 lines · Markus Armbruster

Markus Armbruster (4):
qemu-option: Replace pointless use of g_malloc0() by g_malloc()
qemu-option: Pair g_malloc() with g_free(), not free()
spapr_vio: Pair g_malloc() with g_free(), not free()
usb: Pair g_malloc() with g_free(), not free()

Applied to -trivial, thank you!

/mjt