diff mbox series

[1/2] logging: Fixes memory leak in test-logging.c

Message ID 20200908121022.11-2-luoyonggang@gmail.com (mailing list archive)
State New, archived
Headers show
Series rcu: add uninit destructor for rcu so the pending calls be called before the process exit | expand

Commit Message

Yonggang Luo Sept. 8, 2020, 12:10 p.m. UTC
g_dir_make_tmp Returns the actual name used. This string should be freed with g_free() when not needed any longer
 and is is in the GLib file name encoding. In case of errors, NULL is returned and error will be set.
Use g_autofree to free it properly

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 tests/test-logging.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Philippe Mathieu-Daudé Sept. 8, 2020, 12:22 p.m. UTC | #1
On 9/8/20 2:10 PM, Yonggang Luo wrote:
> g_dir_make_tmp Returns the actual name used. This string should be freed with g_free() when not needed any longer
>  and is is in the GLib file name encoding. In case of errors, NULL is returned and error will be set.
> Use g_autofree to free it properly

Please limit your lines to 80 chars, see CODING_STYLE.rst:

  Line width
  ==========

  Lines should be 80 characters; try not to make them longer.

Also it is recommended to limit commit description to
72 chars. With that addressed:

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

(and please keep the reviewers tags when you repost the
same patch, this way we don't have to review your patches
twice).

> 
> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> ---
>  tests/test-logging.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tests/test-logging.c b/tests/test-logging.c
> index 8a1161de1d..957f6c08cd 100644
> --- a/tests/test-logging.c
> +++ b/tests/test-logging.c
> @@ -196,7 +196,7 @@ static void rmdir_full(gchar const *root)
>  
>  int main(int argc, char **argv)
>  {
> -    gchar *tmp_path = g_dir_make_tmp("qemu-test-logging.XXXXXX", NULL);
> +    g_autofree gchar *tmp_path = g_dir_make_tmp("qemu-test-logging.XXXXXX", NULL);
>      int rc;
>  
>      g_test_init(&argc, &argv, NULL);
>
diff mbox series

Patch

diff --git a/tests/test-logging.c b/tests/test-logging.c
index 8a1161de1d..957f6c08cd 100644
--- a/tests/test-logging.c
+++ b/tests/test-logging.c
@@ -196,7 +196,7 @@  static void rmdir_full(gchar const *root)
 
 int main(int argc, char **argv)
 {
-    gchar *tmp_path = g_dir_make_tmp("qemu-test-logging.XXXXXX", NULL);
+    g_autofree gchar *tmp_path = g_dir_make_tmp("qemu-test-logging.XXXXXX", NULL);
     int rc;
 
     g_test_init(&argc, &argv, NULL);