On Fri, Aug 08, 2014 at 03:02:57PM +0200, Pino Toscano wrote:
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; }
ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v