All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-trivial] [PATCH trivial] init_paths: fix minor memory leak
@ 2014-04-10 14:07 ` Kirill Batuzov
  0 siblings, 0 replies; 3+ messages in thread
From: Kirill Batuzov @ 2014-04-10 14:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, Kirill Batuzov

Fields "name" (created with strdup in new_entry) and "pathname"
(created with g_strdup_printf in new_entry) of pathelem struct should
be freed before the whole struct is.

Signed-off-by: Kirill Batuzov <batuzovk@ispras.ru>
---
 util/path.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/util/path.c b/util/path.c
index 623219e..5c59d9f 100644
--- a/util/path.c
+++ b/util/path.c
@@ -160,7 +160,9 @@ void init_paths(const char *prefix)
     base = new_entry("", NULL, pref_buf);
     base = add_dir_maybe(base);
     if (base->num_entries == 0) {
-        free (base);
+        g_free(base->pathname);
+        free(base->name);
+        free(base);
         base = NULL;
     } else {
         set_parents(base, base);
-- 
1.7.10.4



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [Qemu-devel] [PATCH trivial] init_paths: fix minor memory leak
@ 2014-04-10 14:07 ` Kirill Batuzov
  0 siblings, 0 replies; 3+ messages in thread
From: Kirill Batuzov @ 2014-04-10 14:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, Kirill Batuzov

Fields "name" (created with strdup in new_entry) and "pathname"
(created with g_strdup_printf in new_entry) of pathelem struct should
be freed before the whole struct is.

Signed-off-by: Kirill Batuzov <batuzovk@ispras.ru>
---
 util/path.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/util/path.c b/util/path.c
index 623219e..5c59d9f 100644
--- a/util/path.c
+++ b/util/path.c
@@ -160,7 +160,9 @@ void init_paths(const char *prefix)
     base = new_entry("", NULL, pref_buf);
     base = add_dir_maybe(base);
     if (base->num_entries == 0) {
-        free (base);
+        g_free(base->pathname);
+        free(base->name);
+        free(base);
         base = NULL;
     } else {
         set_parents(base, base);
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-trivial] [PATCH trivial] init_paths: fix minor memory leak
  2014-04-10 14:07 ` [Qemu-devel] " Kirill Batuzov
  (?)
@ 2014-04-27  9:15 ` Michael Tokarev
  -1 siblings, 0 replies; 3+ messages in thread
From: Michael Tokarev @ 2014-04-27  9:15 UTC (permalink / raw)
  To: Kirill Batuzov, qemu-devel; +Cc: qemu-trivial

10.04.2014 18:07, Kirill Batuzov wrote:
> Fields "name" (created with strdup in new_entry) and "pathname"
> (created with g_strdup_printf in new_entry) of pathelem struct should
> be freed before the whole struct is.

Applied to -trivial, thanks!

The fun thing here is that the code _looks_ correct.  I think
it might be better to create proper API for destroying path
elements - new_entry() and its destroying counterpart, free_entry().

/mjt


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-04-27  9:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-10 14:07 [Qemu-trivial] [PATCH trivial] init_paths: fix minor memory leak Kirill Batuzov
2014-04-10 14:07 ` [Qemu-devel] " Kirill Batuzov
2014-04-27  9:15 ` [Qemu-trivial] " Michael Tokarev

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.