Skip to contentSkip to conversation

Changed malloc to g_malloc, free to g_free in linux-user/qemu.h

PATCH In review Md Haris Iqbal 3 participants 10 messages Mar 23, 2016 – Sep 14, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Changed malloc to g_malloc, free to g_free in linux-user/qemu.h

---
 linux-user/qemu.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/qemu.h +2 -2
index 26b0ba2..3c3fd15 100644
@@ -381,7 +381,7 @@ static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy
 #ifdef DEBUG_REMAP
     {
         void *addr;
-        addr = malloc(len);
+        addr = g_malloc(len);
         if (copy)
             memcpy(addr, g2h(guest_addr), len);
         else
@@ -407,7 +407,7 @@ static inline void unlock_user(void *host_ptr, abi_ulong guest_addr,
         return;
     if (len > 0)
         memcpy(g2h(guest_addr), host_ptr, len);
-    free(host_ptr);
+    g_free(host_ptr);
 #endif
 }
 
Signature · 1 line
1.9.1
#1 lore raw

Hi,

Can I get a respond for this patch. Is it complete, or did I miss something?

Quoted 30 lines · Md Haris Iqbal
---
 linux-user/qemu.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/qemu.h +2 -3
index 26b0ba2..3c3fd15 100644
@@ -381,7 +381,7 @@ static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy
 #ifdef DEBUG_REMAP
     {
         void *addr;
-        addr = malloc(len);
+        addr = g_malloc(len);
         if (copy)
             memcpy(addr, g2h(guest_addr), len);
         else
@@ -407,7 +407,7 @@ static inline void unlock_user(void *host_ptr, abi_ulong guest_addr,
         return;
     if (len > 0)
         memcpy(g2h(guest_addr), host_ptr, len);
-    free(host_ptr);
+    g_free(host_ptr);
 #endif
 }
 
--

1.9.1

Signature · 6 lines
With regards,

Md Haris Iqbal,
Placement Coordinator, MTech IT
NITK Surathkal,
Contact: +91 8861996962
#2 lore raw

Hi,

Patch is attached in the previous mail. Looking forward to your review.

Quoted 47 lines · haris iqbal

Hi,

Can I get a respond for this patch. Is it complete, or did I miss something?

Quoted 28 lines · Md Haris Iqbal
---
 linux-user/qemu.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/qemu.h +2 -3
index 26b0ba2..3c3fd15 100644
@@ -381,7 +381,7 @@ static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy
 #ifdef DEBUG_REMAP
     {
         void *addr;
-        addr = malloc(len);
+        addr = g_malloc(len);
         if (copy)
             memcpy(addr, g2h(guest_addr), len);
         else
@@ -407,7 +407,7 @@ static inline void unlock_user(void *host_ptr, abi_ulong guest_addr,
         return;
     if (len > 0)
         memcpy(g2h(guest_addr), host_ptr, len);
-    free(host_ptr);
+    g_free(host_ptr);
 #endif
 }
 
--
Quoted 2 lines

1.9.1

--

With regards,

Md Haris Iqbal,
Placement Coordinator, MTech IT
NITK Surathkal,
Contact: +91 8861996962

Signature · 6 lines
With regards,

Md Haris Iqbal,
Placement Coordinator, MTech IT
NITK Surathkal,
Contact: +91 8861996962
#3 lore raw
In reply to Md Haris Iqbal
Quoted 19 lines · Md Haris Iqbal
---
 linux-user/qemu.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/qemu.h +1 -1
index 26b0ba2..3c3fd15 100644
@@ -381,7 +381,7 @@ static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy
 #ifdef DEBUG_REMAP
     {
         void *addr;
-        addr = malloc(len);
+        addr = g_malloc(len);
         if (copy)
             memcpy(addr, g2h(guest_addr), len);
         else

linux-user/qemu.h static inline void unlock_user(void *host_ptr, abi_ulong guest_addr, · line 412

Quoted 7 lines
linux-user/qemu.h +1 -1
@@ -407,7 +407,7 @@ static inline void unlock_user(void *host_ptr, abi_ulong guest_addr,
         return;
     if (len > 0)
         memcpy(g2h(guest_addr), host_ptr, len);
-    free(host_ptr);
+    g_free(host_ptr);
 #endif
 }

If I understand correctly either lock_user() or lock_user_string() may be followed by unlock_user(). If you change unlock_user() to g_free() then you also need to change lock_user_string() to g_malloc() to avoid a malloc()/g_free() mismatch.

#4 lore raw
Quoted 24 lines · Stefan Hajnoczi
Quoted 23 lines · Md Haris Iqbal
---
 linux-user/qemu.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/qemu.h +1 -2
index 26b0ba2..3c3fd15 100644
@@ -381,7 +381,7 @@ static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy
 #ifdef DEBUG_REMAP
     {
         void *addr;
-        addr = malloc(len);
+        addr = g_malloc(len);
         if (copy)
             memcpy(addr, g2h(guest_addr), len);
         else
@@ -407,7 +407,7 @@ static inline void unlock_user(void *host_ptr, abi_ulong guest_addr,
         return;
     if (len > 0)
         memcpy(g2h(guest_addr), host_ptr, len);
-    free(host_ptr);
Quoted 8 lines

linux-user/qemu.h static inline void unlock_user(void *host_ptr, abi_ulong guest_addr, · line 412

Quoted 3 lines
linux-user/qemu.h +1 -0
+    g_free(host_ptr);
 #endif
 }

If I understand correctly either lock_user() or lock_user_string() may be followed by unlock_user(). If you change unlock_user() to g_free() then you also need to change lock_user_string() to g_malloc() to avoid a malloc()/g_free() mismatch.

lock_user_string() does not use malloc itself, but calls lock_user() from itself.

Signature · 6 lines
With regards,

Md Haris Iqbal,
Placement Coordinator, MTech IT
NITK Surathkal,
Contact: +91 8861996962
#5 lore raw
Quoted 34 lines · haris iqbal
Quoted 24 lines · Stefan Hajnoczi
Quoted 23 lines · Md Haris Iqbal
---
 linux-user/qemu.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/qemu.h +1 -2
index 26b0ba2..3c3fd15 100644
@@ -381,7 +381,7 @@ static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy
 #ifdef DEBUG_REMAP
     {
         void *addr;
-        addr = malloc(len);
+        addr = g_malloc(len);
         if (copy)
             memcpy(addr, g2h(guest_addr), len);
         else
@@ -407,7 +407,7 @@ static inline void unlock_user(void *host_ptr, abi_ulong guest_addr,
         return;
     if (len > 0)
         memcpy(g2h(guest_addr), host_ptr, len);
-    free(host_ptr);
Quoted 8 lines

linux-user/qemu.h static inline void unlock_user(void *host_ptr, abi_ulong guest_addr, · line 412

Quoted 3 lines
linux-user/qemu.h +1 -0
+    g_free(host_ptr);
 #endif
 }

If I understand correctly either lock_user() or lock_user_string() may be followed by unlock_user(). If you change unlock_user() to g_free() then you also need to change lock_user_string() to g_malloc() to avoid a malloc()/g_free() mismatch.

Quoted 2 lines

lock_user_string() does not use malloc itself, but calls lock_user() from itself.

You are right. The reason I got confused is because there are 3 versions of lock_user(): linux-user, bsd-user, and include/exec/softmmu-semi.h.

Please send equivalent patches for the other 2 versions as well. This way they stay consistent.

Thanks,
Stefan

#6 lore raw
Quoted 38 lines · Stefan Hajnoczi
Quoted 34 lines · haris iqbal
Quoted 24 lines · Stefan Hajnoczi
Quoted 23 lines · Md Haris Iqbal
---
 linux-user/qemu.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/qemu.h +1 -2
index 26b0ba2..3c3fd15 100644
@@ -381,7 +381,7 @@ static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy
 #ifdef DEBUG_REMAP
     {
         void *addr;
-        addr = malloc(len);
+        addr = g_malloc(len);
         if (copy)
             memcpy(addr, g2h(guest_addr), len);
         else
@@ -407,7 +407,7 @@ static inline void unlock_user(void *host_ptr, abi_ulong guest_addr,
         return;
     if (len > 0)
         memcpy(g2h(guest_addr), host_ptr, len);
-    free(host_ptr);
Quoted 8 lines

linux-user/qemu.h static inline void unlock_user(void *host_ptr, abi_ulong guest_addr, · line 412

Quoted 3 lines
linux-user/qemu.h +1 -0
+    g_free(host_ptr);
 #endif
 }

If I understand correctly either lock_user() or lock_user_string() may be followed by unlock_user(). If you change unlock_user() to g_free() then you also need to change lock_user_string() to g_malloc() to avoid a malloc()/g_free() mismatch.

Quoted 2 lines

lock_user_string() does not use malloc itself, but calls lock_user() from itself.

Quoted 6 lines

You are right. The reason I got confused is because there are 3 versions of lock_user(): linux-user, bsd-user, and include/exec/softmmu-semi.h.

Please send equivalent patches for the other 2 versions as well. This way they stay consistent.

Will do. Actually as they different files, I was told to send patches separately.

And I wanted to wait till this one is reviewed, so I don't repeat any mistake if there are in this one.

Quoted 3 lines

Thanks,
Stefan

Signature · 6 lines
With regards,

Md Haris Iqbal,
Placement Coordinator, MTech IT
NITK Surathkal,
Contact: +91 8861996962
#7 lore raw

Just a reminder. any more changes needed for this patch? or can it be merged?

Quoted 66 lines · haris iqbal
Quoted 38 lines · Stefan Hajnoczi
Quoted 34 lines · haris iqbal
Quoted 24 lines · Stefan Hajnoczi
Quoted 23 lines · Md Haris Iqbal
---
 linux-user/qemu.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/qemu.h +1 -2
index 26b0ba2..3c3fd15 100644
@@ -381,7 +381,7 @@ static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy
 #ifdef DEBUG_REMAP
     {
         void *addr;
-        addr = malloc(len);
+        addr = g_malloc(len);
         if (copy)
             memcpy(addr, g2h(guest_addr), len);
         else
@@ -407,7 +407,7 @@ static inline void unlock_user(void *host_ptr, abi_ulong guest_addr,
         return;
     if (len > 0)
         memcpy(g2h(guest_addr), host_ptr, len);
-    free(host_ptr);
Quoted 8 lines

linux-user/qemu.h static inline void unlock_user(void *host_ptr, abi_ulong guest_addr, · line 412

Quoted 3 lines
linux-user/qemu.h +1 -0
+    g_free(host_ptr);
 #endif
 }

If I understand correctly either lock_user() or lock_user_string() may be followed by unlock_user(). If you change unlock_user() to g_free() then you also need to change lock_user_string() to g_malloc() to avoid a malloc()/g_free() mismatch.

Quoted 2 lines

lock_user_string() does not use malloc itself, but calls lock_user() from itself.

Quoted 6 lines

You are right. The reason I got confused is because there are 3 versions of lock_user(): linux-user, bsd-user, and include/exec/softmmu-semi.h.

Please send equivalent patches for the other 2 versions as well. This way they stay consistent.

Will do. Actually as they different files, I was told to send patches separately.

And I wanted to wait till this one is reviewed, so I don't repeat any mistake if there are in this one.

Quoted 3 lines

Thanks,
Stefan

--

With regards,

Md Haris Iqbal,
Placement Coordinator, MTech IT
NITK Surathkal,
Contact: +91 8861996962

Signature · 6 lines
With regards,

Md Haris Iqbal,
Placement Coordinator, MTech IT
NITK Surathkal,
Contact: +91 8861996962
#9 lore raw
In reply to Md Haris Iqbal
Quoted 19 lines · Md Haris Iqbal
---
 linux-user/qemu.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/qemu.h +1 -1
index 26b0ba2..3c3fd15 100644
@@ -381,7 +381,7 @@ static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy
 #ifdef DEBUG_REMAP
     {
         void *addr;
-        addr = malloc(len);
+        addr = g_malloc(len);
         if (copy)
             memcpy(addr, g2h(guest_addr), len);
         else

linux-user/qemu.h static inline void unlock_user(void *host_ptr, abi_ulong guest_addr, · line 412

Quoted 7 lines
linux-user/qemu.h +1 -1
@@ -407,7 +407,7 @@ static inline void unlock_user(void *host_ptr, abi_ulong guest_addr,
         return;
     if (len > 0)
         memcpy(g2h(guest_addr), host_ptr, len);
-    free(host_ptr);
+    g_free(host_ptr);
 #endif
 }

This is a very old patch, somehow missed by me at that time. Applied to -trivial now, thank you!

/mjt