diff mbox

[trivial] init_paths: fix minor memory leak

Message ID 1397138878-11770-1-git-send-email-batuzovk@ispras.ru
State New
Headers show

Commit Message

Kirill Batuzov April 10, 2014, 2:07 p.m. UTC
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(-)

Comments

Michael Tokarev April 27, 2014, 9:15 a.m. UTC | #1
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
diff mbox

Patch

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);