qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH v3 12/54] tests/qtest: hd-geo-test: Avoid using hardcoded /tm


From: Thomas Huth
Subject: Re: [PATCH v3 12/54] tests/qtest: hd-geo-test: Avoid using hardcoded /tmp
Date: Mon, 26 Sep 2022 17:38:20 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0

On 25/09/2022 13.29, Bin Meng wrote:
From: Bin Meng <bin.meng@windriver.com>

This case was written to use hardcoded /tmp directory for temporary
files. Update to use g_file_open_tmp() for a portable implementation.

Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

Changes in v3:
- Split to a separate patch
- Ensure g_autofree variable is initialized
- Use g_steal_pointer() in create_test_img()

  tests/qtest/hd-geo-test.c | 25 +++++++++++--------------
  1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c
index 413cf964c0..455bc5db5c 100644
--- a/tests/qtest/hd-geo-test.c
+++ b/tests/qtest/hd-geo-test.c
@@ -27,20 +27,19 @@
static char *create_test_img(int secs)
  {
-    char *template = strdup("/tmp/qtest.XXXXXX");
+    g_autofree char *template = NULL;
      int fd, ret;
- fd = mkstemp(template);
+    fd = g_file_open_tmp("qtest.XXXXXX", &template, NULL);
      g_assert(fd >= 0);
      ret = ftruncate(fd, (off_t)secs * 512);
      close(fd);
if (ret) {
-        free(template);
          template = NULL;
      }
- return template;
+    return g_steal_pointer(&template);

Just a matter of taste, but in this case, I'd rather prefer to not use g_autofree + g_steal_pointer and simply replace the "free" with a "g_free" instead.

 Thomas




reply via email to

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