mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-02 12:01:32 +01:00
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:
parent
b1e8e0d4b9
commit
c14ef10fc3
@ -114,6 +114,7 @@ ccparray_put (ccparray_t *cpa, const char *value)
|
|||||||
}
|
}
|
||||||
for (n=0; n < cpa->size; n++)
|
for (n=0; n < cpa->size; n++)
|
||||||
newarray[n] = cpa->array[n];
|
newarray[n] = cpa->array[n];
|
||||||
|
xfree (cpa->array);
|
||||||
cpa->array = newarray;
|
cpa->array = newarray;
|
||||||
cpa->size = newsize;
|
cpa->size = newsize;
|
||||||
|
|
||||||
|
@ -538,6 +538,7 @@ do_make_filename (int xmode, const char *first_part, va_list arg_ptr)
|
|||||||
home_buffer = xtrymalloc (n);
|
home_buffer = xtrymalloc (n);
|
||||||
if (!home_buffer)
|
if (!home_buffer)
|
||||||
{
|
{
|
||||||
|
xfree (home);
|
||||||
xfree (name);
|
xfree (name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -556,6 +557,7 @@ do_make_filename (int xmode, const char *first_part, va_list arg_ptr)
|
|||||||
else
|
else
|
||||||
strcpy (stpcpy (stpcpy (p, home), "/"), name);
|
strcpy (stpcpy (stpcpy (p, home), "/"), name);
|
||||||
|
|
||||||
|
xfree (home);
|
||||||
xfree (name);
|
xfree (name);
|
||||||
name = home_buffer;
|
name = home_buffer;
|
||||||
/* Let's do a simple compression to catch the most common
|
/* Let's do a simple compression to catch the most common
|
||||||
|
@ -234,6 +234,7 @@ test_bin2hex (void)
|
|||||||
fail (0);
|
fail (0);
|
||||||
else if (strcmp (p, hexstuff))
|
else if (strcmp (p, hexstuff))
|
||||||
fail (0);
|
fail (0);
|
||||||
|
xfree (p);
|
||||||
|
|
||||||
p = bin2hex (stuff, (size_t)(-1), NULL);
|
p = bin2hex (stuff, (size_t)(-1), NULL);
|
||||||
if (p)
|
if (p)
|
||||||
@ -266,6 +267,7 @@ test_bin2hexcolon (void)
|
|||||||
fail (0);
|
fail (0);
|
||||||
else if (strcmp (p, hexstuff))
|
else if (strcmp (p, hexstuff))
|
||||||
fail (0);
|
fail (0);
|
||||||
|
xfree (p);
|
||||||
|
|
||||||
p = bin2hexcolon (stuff, (size_t)(-1), NULL);
|
p = bin2hexcolon (stuff, (size_t)(-1), NULL);
|
||||||
if (p)
|
if (p)
|
||||||
|
@ -190,6 +190,8 @@ main (int argc, char *argv[])
|
|||||||
n ++;
|
n ++;
|
||||||
}
|
}
|
||||||
assert (n == 10 + (strlen (content) - 10) / 2);
|
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). */
|
/* The string should have been truncated (max_len == 0). */
|
||||||
assert (max_len == 0);
|
assert (max_len == 0);
|
||||||
free (buffer);
|
free (buffer);
|
||||||
|
|
||||||
|
iobuf_close (iobuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -279,10 +283,12 @@ main (int argc, char *argv[])
|
|||||||
int c;
|
int c;
|
||||||
int n;
|
int n;
|
||||||
int lastc = 0;
|
int lastc = 0;
|
||||||
|
struct content_filter_state *state;
|
||||||
|
|
||||||
iobuf = iobuf_temp_with_content (content, strlen(content));
|
iobuf = iobuf_temp_with_content (content, strlen(content));
|
||||||
rc = iobuf_push_filter (iobuf,
|
rc = iobuf_push_filter (iobuf,
|
||||||
content_filter, content_filter_new (content2));
|
content_filter,
|
||||||
|
state=content_filter_new (content2));
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
@ -309,6 +315,9 @@ main (int argc, char *argv[])
|
|||||||
/* printf ("%d: '%c' (%d)\n", n, c, c); */
|
/* 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
|
/* 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 (n == strlen (content) + 2 * (strlen (content2) + 1));
|
||||||
assert (strcmp (buffer, "0123456789aabbcc") == 0);
|
assert (strcmp (buffer, "0123456789aabbcc") == 0);
|
||||||
|
|
||||||
|
iobuf_close (iobuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -373,6 +384,8 @@ main (int argc, char *argv[])
|
|||||||
assert (n == 2);
|
assert (n == 2);
|
||||||
assert (buffer[0] == '3');
|
assert (buffer[0] == '3');
|
||||||
assert (buffer[1] == '7');
|
assert (buffer[1] == '7');
|
||||||
|
|
||||||
|
iobuf_close (iobuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -87,6 +87,8 @@ run_test (void)
|
|||||||
fail (idx);
|
fail (idx);
|
||||||
else if (strcmp (mbox, testtbl[idx].mbox))
|
else if (strcmp (mbox, testtbl[idx].mbox))
|
||||||
fail (idx);
|
fail (idx);
|
||||||
|
|
||||||
|
xfree (mbox);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,19 +387,19 @@ run_modification_tests (void)
|
|||||||
if (private_key_mode)
|
if (private_key_mode)
|
||||||
{
|
{
|
||||||
err = nvc_set_private_key (pk, key);
|
err = nvc_set_private_key (pk, key);
|
||||||
gcry_sexp_release (key);
|
|
||||||
assert (err == 0);
|
assert (err == 0);
|
||||||
|
|
||||||
buf = nvc_to_string (pk);
|
buf = nvc_to_string (pk);
|
||||||
assert (strcmp (buf, "Key: (hello world)\n") == 0);
|
assert (strcmp (buf, "Key: (hello world)\n") == 0);
|
||||||
xfree (buf);
|
xfree (buf);
|
||||||
nvc_release (pk);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
err = nvc_set_private_key (pk, key);
|
err = nvc_set_private_key (pk, key);
|
||||||
assert (gpg_err_code (err) == GPG_ERR_MISSING_KEY);
|
assert (gpg_err_code (err) == GPG_ERR_MISSING_KEY);
|
||||||
}
|
}
|
||||||
|
gcry_sexp_release (key);
|
||||||
|
nvc_release (pk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -223,6 +223,7 @@ test_strconcat (void)
|
|||||||
fail (0);
|
fail (0);
|
||||||
else if (errno != EINVAL)
|
else if (errno != EINVAL)
|
||||||
fail (0);
|
fail (0);
|
||||||
|
xfree (out);
|
||||||
|
|
||||||
#if __GNUC__ < 4 /* gcc 4.0 has a sentinel attribute. */
|
#if __GNUC__ < 4 /* gcc 4.0 has a sentinel attribute. */
|
||||||
out = strconcat (NULL);
|
out = strconcat (NULL);
|
||||||
@ -232,6 +233,8 @@ test_strconcat (void)
|
|||||||
out = strconcat (NULL, NULL);
|
out = strconcat (NULL, NULL);
|
||||||
if (!out || *out)
|
if (!out || *out)
|
||||||
fail (1);
|
fail (1);
|
||||||
|
xfree (out);
|
||||||
|
|
||||||
out = strconcat ("", NULL);
|
out = strconcat ("", NULL);
|
||||||
if (!out || *out)
|
if (!out || *out)
|
||||||
fail (1);
|
fail (1);
|
||||||
@ -283,6 +286,7 @@ test_xstrconcat (void)
|
|||||||
"1", "2", "3", "4", "5", "6", "7", NULL);
|
"1", "2", "3", "4", "5", "6", "7", NULL);
|
||||||
if (!out)
|
if (!out)
|
||||||
fail (0);
|
fail (0);
|
||||||
|
xfree (out);
|
||||||
|
|
||||||
#if __GNUC__ < 4 /* gcc 4.0 has a sentinel attribute. */
|
#if __GNUC__ < 4 /* gcc 4.0 has a sentinel attribute. */
|
||||||
out = xstrconcat (NULL);
|
out = xstrconcat (NULL);
|
||||||
@ -292,6 +296,8 @@ test_xstrconcat (void)
|
|||||||
out = xstrconcat (NULL, NULL);
|
out = xstrconcat (NULL, NULL);
|
||||||
if (!out)
|
if (!out)
|
||||||
fail (1);
|
fail (1);
|
||||||
|
xfree (out);
|
||||||
|
|
||||||
out = xstrconcat ("", NULL);
|
out = xstrconcat ("", NULL);
|
||||||
if (!out || *out)
|
if (!out || *out)
|
||||||
fail (1);
|
fail (1);
|
||||||
@ -534,6 +540,7 @@ test_strsplit (void)
|
|||||||
fail (tidx * 1000 + i + 1);
|
fail (tidx * 1000 + i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xfree (fields);
|
||||||
xfree (s2);
|
xfree (s2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,8 @@ test_strlist_rev (void)
|
|||||||
fail (2);
|
fail (2);
|
||||||
if (s->next->next->next)
|
if (s->next->next->next)
|
||||||
fail (2);
|
fail (2);
|
||||||
|
|
||||||
|
free_strlist (s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user