common: Fix memory leaks.

* common/ccparray.c (ccparray_put): Free old array.
* common/stringhelp.c (do_make_filename): Free 'home'.
* common/t-convert.c: Fix trivial memory leaks.
* common/t-iobuf.c: Likewise.
* common/t-mbox-util.c: Likewise.
* common/t-name-value.c: Likewise.
* common/t-stringhelp.c: Likewise.
* common/t-strlist.c: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
This commit is contained in:
Justus Winter 2016-06-28 17:59:17 +02:00
parent b1e8e0d4b9
commit c14ef10fc3
8 changed files with 32 additions and 3 deletions

View File

@ -114,6 +114,7 @@ ccparray_put (ccparray_t *cpa, const char *value)
}
for (n=0; n < cpa->size; n++)
newarray[n] = cpa->array[n];
xfree (cpa->array);
cpa->array = newarray;
cpa->size = newsize;

View File

@ -538,6 +538,7 @@ do_make_filename (int xmode, const char *first_part, va_list arg_ptr)
home_buffer = xtrymalloc (n);
if (!home_buffer)
{
xfree (home);
xfree (name);
return NULL;
}
@ -556,6 +557,7 @@ do_make_filename (int xmode, const char *first_part, va_list arg_ptr)
else
strcpy (stpcpy (stpcpy (p, home), "/"), name);
xfree (home);
xfree (name);
name = home_buffer;
/* Let's do a simple compression to catch the most common

View File

@ -234,6 +234,7 @@ test_bin2hex (void)
fail (0);
else if (strcmp (p, hexstuff))
fail (0);
xfree (p);
p = bin2hex (stuff, (size_t)(-1), NULL);
if (p)
@ -266,6 +267,7 @@ test_bin2hexcolon (void)
fail (0);
else if (strcmp (p, hexstuff))
fail (0);
xfree (p);
p = bin2hexcolon (stuff, (size_t)(-1), NULL);
if (p)

View File

@ -190,6 +190,8 @@ main (int argc, char *argv[])
n ++;
}
assert (n == 10 + (strlen (content) - 10) / 2);
iobuf_close (iobuf);
}
@ -266,6 +268,8 @@ main (int argc, char *argv[])
/* The string should have been truncated (max_len == 0). */
assert (max_len == 0);
free (buffer);
iobuf_close (iobuf);
}
{
@ -279,10 +283,12 @@ main (int argc, char *argv[])
int c;
int n;
int lastc = 0;
struct content_filter_state *state;
iobuf = iobuf_temp_with_content (content, strlen(content));
rc = iobuf_push_filter (iobuf,
content_filter, content_filter_new (content2));
content_filter,
state=content_filter_new (content2));
assert (rc == 0);
n = 0;
@ -309,6 +315,9 @@ main (int argc, char *argv[])
/* printf ("%d: '%c' (%d)\n", n, c, c); */
}
}
iobuf_close (iobuf);
free (state);
}
/* Write some data to a temporary filter. Push a new filter. The
@ -346,6 +355,8 @@ main (int argc, char *argv[])
assert (n == strlen (content) + 2 * (strlen (content2) + 1));
assert (strcmp (buffer, "0123456789aabbcc") == 0);
iobuf_close (iobuf);
}
{
@ -373,6 +384,8 @@ main (int argc, char *argv[])
assert (n == 2);
assert (buffer[0] == '3');
assert (buffer[1] == '7');
iobuf_close (iobuf);
}
return 0;

View File

@ -87,6 +87,8 @@ run_test (void)
fail (idx);
else if (strcmp (mbox, testtbl[idx].mbox))
fail (idx);
xfree (mbox);
}
}

View File

@ -387,19 +387,19 @@ run_modification_tests (void)
if (private_key_mode)
{
err = nvc_set_private_key (pk, key);
gcry_sexp_release (key);
assert (err == 0);
buf = nvc_to_string (pk);
assert (strcmp (buf, "Key: (hello world)\n") == 0);
xfree (buf);
nvc_release (pk);
}
else
{
err = nvc_set_private_key (pk, key);
assert (gpg_err_code (err) == GPG_ERR_MISSING_KEY);
}
gcry_sexp_release (key);
nvc_release (pk);
}

View File

@ -223,6 +223,7 @@ test_strconcat (void)
fail (0);
else if (errno != EINVAL)
fail (0);
xfree (out);
#if __GNUC__ < 4 /* gcc 4.0 has a sentinel attribute. */
out = strconcat (NULL);
@ -232,6 +233,8 @@ test_strconcat (void)
out = strconcat (NULL, NULL);
if (!out || *out)
fail (1);
xfree (out);
out = strconcat ("", NULL);
if (!out || *out)
fail (1);
@ -283,6 +286,7 @@ test_xstrconcat (void)
"1", "2", "3", "4", "5", "6", "7", NULL);
if (!out)
fail (0);
xfree (out);
#if __GNUC__ < 4 /* gcc 4.0 has a sentinel attribute. */
out = xstrconcat (NULL);
@ -292,6 +296,8 @@ test_xstrconcat (void)
out = xstrconcat (NULL, NULL);
if (!out)
fail (1);
xfree (out);
out = xstrconcat ("", NULL);
if (!out || *out)
fail (1);
@ -534,6 +540,7 @@ test_strsplit (void)
fail (tidx * 1000 + i + 1);
}
xfree (fields);
xfree (s2);
}
}

View File

@ -67,6 +67,8 @@ test_strlist_rev (void)
fail (2);
if (s->next->next->next)
fail (2);
free_strlist (s);
}