Fix the memory issues in the implementation that uses no -p nor -i:
- use add_string_nodup to add results from get_blkid_tag (which returns
new strings), so those strings are not leaked
- use free_stringslen to clean the hash on error, as in such case the
stringbuf will not be terminated with a null entry, thus causing
free_strings to crash
---
daemon/blkid.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/daemon/blkid.c b/daemon/blkid.c
index 83ff355..b98c155 100644
--- a/daemon/blkid.c
+++ b/daemon/blkid.c
@@ -197,19 +197,19 @@ blkid_without_p_i_opt(const char *device)
if (add_string (&ret, "TYPE") == -1) goto error;
s = get_blkid_tag (device, "TYPE");
if (s == NULL) goto error;
- if (add_string (&ret, s) == -1)
+ if (add_string_nodup (&ret, s) == -1)
goto error;
if (add_string (&ret, "LABEL") == -1) goto error;
s = get_blkid_tag (device, "LABEL");
if (s == NULL) goto error;
- if (add_string (&ret, s) == -1)
+ if (add_string_nodup (&ret, s) == -1)
goto error;
if (add_string (&ret, "UUID") == -1) goto error;
s = get_blkid_tag (device, "UUID");
if (s == NULL) goto error;
- if (add_string (&ret, s) == -1)
+ if (add_string_nodup (&ret, s) == -1)
goto error;
if (end_stringsbuf (&ret) == -1) goto error;
@@ -217,7 +217,7 @@ blkid_without_p_i_opt(const char *device)
return ret.argv;
error:
if (ret.argv)
- free_strings (ret.argv);
+ free_stringslen (ret.argv, ret.size);
return NULL;
}
--
1.9.3