Re: [PATCH 1/2] kernel-shark-qt: Deal with the "no tasks" case in kshark_get_task_pids()

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

 



Hi Steven,
Should I send this patch again?

Thanks!
Yordan


On 11.07.2018 17:08, Yordan Karadzhov (VMware) wrote:

What about doing it this way:

diff --git a/kernel-shark-qt/src/libkshark.c b/kernel-shark-qt/src/libkshark.c
index 668b6df8..34daa25e 100644
--- a/kernel-shark-qt/src/libkshark.c
+++ b/kernel-shark-qt/src/libkshark.c
@@ -303,12 +303,17 @@ ssize_t kshark_get_task_pids(struct kshark_context *kshark_ctx, int **pids)
          }
      }
-    temp_pids = realloc(*pids, pid_count * sizeof(int));
-    if (!temp_pids)
-        goto fail;
+    if (pid_count) {
+        temp_pids = realloc(*pids, pid_count * sizeof(int));
+        if (!temp_pids)
+            goto fail;
-    /* Paranoid: In the unlikely case of shrinking *pids, realloc moves it */
-    *pids = temp_pids;
+        /* Paranoid: In the unlikely case of shrinking *pids, realloc moves it */
+        *pids = temp_pids;
+    } else {
+        free(*pids);
+        *pids = NULL;
+    }
      return pid_count;

Yes, this way is better.

Thanks!
Yordan



?

-- Steve



[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux