Skip to contentSkip to conversation

linux-user/syscall.c: malloc to g_try_malloc

PATCH In review Ahmed Abouzied 2 participants 2 messages Jan 4, 2022 – Jan 5, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user/syscall.c: malloc to g_try_malloc

Use g_try_malloc instead of malloc to alocate the target ifconfig. Also replace the corresponding free with g_free.

---

Hello,

I noticed that there was a malloc call in this file. It seems that it was added by the commit 22e4a267 (3 years ago) which was after the commit 0e173b24 (6 years ago) that replaced malloc calls with glib alternative calls.

There is no issue for this on Gitlab. Should I have created an issue first?

Best regards,

 linux-user/syscall.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/syscall.c +2 -2
index 56a3e17183..715f9430e1 100644
@@ -4867,7 +4867,7 @@ static abi_long do_ioctl_ifconf(const IOCTLEntry *ie, uint8_t *buf_temp,
              * We can't fit all the extents into the fixed size buffer.
              * Allocate one that is large enough and use it instead.
              */
-            host_ifconf = malloc(outbufsz);
+            host_ifconf = g_try_malloc(outbufsz);
             if (!host_ifconf) {
                 return -TARGET_ENOMEM;
             }
@@ -4915,7 +4915,7 @@ static abi_long do_ioctl_ifconf(const IOCTLEntry *ie, uint8_t *buf_temp,
     }
 
     if (free_buf) {
-        free(host_ifconf);
+        g_free(host_ifconf);
     }
 
     return ret;
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw

Le 04/01/2022 à 15:46, Ahmed Abouzied a écrit :

Quoted 34 lines

Use g_try_malloc instead of malloc to alocate the target ifconfig. Also replace the corresponding free with g_free.

---

Hello,

I noticed that there was a malloc call in this file. It seems that it was added by the commit 22e4a267 (3 years ago) which was after the commit 0e173b24 (6 years ago) that replaced malloc calls with glib alternative calls.

There is no issue for this on Gitlab. Should I have created an issue first?

Best regards,

  linux-user/syscall.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/syscall.c +1 -1
index 56a3e17183..715f9430e1 100644
@@ -4867,7 +4867,7 @@ static abi_long do_ioctl_ifconf(const IOCTLEntry *ie, uint8_t *buf_temp,
               * We can't fit all the extents into the fixed size buffer.
               * Allocate one that is large enough and use it instead.
               */
-            host_ifconf = malloc(outbufsz);
+            host_ifconf = g_try_malloc(outbufsz);
              if (!host_ifconf) {
                  return -TARGET_ENOMEM;
              }

linux-user/syscall.c static abi_long do_ioctl_ifconf(const IOCTLEntry *ie, uint8_t *buf_temp, · line 4921

Quoted 8 lines
linux-user/syscall.c +1 -1
@@ -4915,7 +4915,7 @@ static abi_long do_ioctl_ifconf(const IOCTLEntry *ie, uint8_t *buf_temp,
      }
 
      if (free_buf) {
-        free(host_ifconf);
+        g_free(host_ifconf);
      }
 
      return ret;