qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 5/8] util/compatfd.c: Replaced a malloc with GLib's variant


From: Thomas Huth
Subject: Re: [PATCH 5/8] util/compatfd.c: Replaced a malloc with GLib's variant
Date: Mon, 15 Mar 2021 07:10:04 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0

On 14/03/2021 04.23, Mahmoud Mandour wrote:
Replaced a malloc() call and its respective free() call with
GLib's g_try_malloc() and g_free().

Also, did slight styling changes that were producing
style errors when using the checkpatch.pl script against
the file.

If it's unrelated, then maybe better do it in a separate patch.

Signed-off-by: Mahmoud Mandour <ma.mandourr@gmail.com>
---
  util/compatfd.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/util/compatfd.c b/util/compatfd.c
index ee47dd8089..834ddd0573 100644
--- a/util/compatfd.c
+++ b/util/compatfd.c
@@ -20,8 +20,7 @@
  #include <sys/syscall.h>
  #endif
-struct sigfd_compat_info
-{
+struct sigfd_compat_info {
      sigset_t mask;
      int fd;
  };
@@ -53,8 +52,9 @@ static void *sigwait_compat(void *opaque)
len = write(info->fd, (char *)&buffer + offset,
                              sizeof(buffer) - offset);
-                if (len == -1 && errno == EINTR)
+                if (len == -1 && errno == EINTR) {
                      continue;
+                }
if (len <= 0) {
                      return NULL;
@@ -72,14 +72,14 @@ static int qemu_signalfd_compat(const sigset_t *mask)
      QemuThread thread;
      int fds[2];
- info = malloc(sizeof(*info));
+    info = g_try_malloc(sizeof(*info));
      if (info == NULL) {
          errno = ENOMEM;
          return -1;
      }

Since this is only a very small allocation, I think it would be better to use g_malloc() here and then simply remove the "if (info == NULL) ..." part.

 Thomas




reply via email to

[Prev in Thread] Current Thread [Next in Thread]