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 <[email protected]>
---
  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