summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2019-03-10 14:05:09 +0100
committerBruno Haible <bruno@clisp.org>2019-03-10 14:05:09 +0100
commit8c96eb80bdf60a539678d2cda41ba9b9fa167b48 (patch)
tree5d64f028e906968d1ef76c8d14a933b9c0060de5 /tests
parentfcf959577b3a02b2502aa10906def10aacf77387 (diff)
downloadgnulib-8c96eb80bdf60a539678d2cda41ba9b9fa167b48.tar.gz
tests: Free allocated memory.
Reported by <deltatau@protonmail.com> via Assaf Gordon. * tests/test-astrxfrm.c (main): Free allocated memory. * tests/test-bitset.c (compare, check_attributes): Free allocated bitsets. * tests/test-filenamecat.c (main): Free allocated memory. * tests/test-freadahead.c (main): Free allocated memory and close stdin. * tests/test-freadptr.c (main): Likewise. * tests/test-freadptr2.c (main): Free allocated memory. * tests/test-freadseek.c (main): Likewise. * tests/test-gc-arcfour.c (main): Close allocated context. * tests/test-gc-arctwo.c (main): Likewise. * tests/test-gc-des.c (main): Close all allocated contexts. * tests/test-pipe-filter-gi1.c (main): Free allocated memory. * tests/test-pipe-filter-ii1.c (main): Likewise. * tests/test-posix_spawn_file_actions_addchdir.c (main): Destroy the allocated file actions. * tests/test-posix_spawn_file_actions_addclose.c (main): Likewise. * tests/test-posix_spawn_file_actions_adddup2.c (main): Likewise. * tests/test-posix_spawn_file_actions_addopen.c (main): Likewise. * tests/test-sameacls.c (main): Free allocated memory and ACLs. * tests/test-strfmon_l.c (main): Free allocated locales. * tests/test-striconveh.c (main): Free allocated iconv_t objects. * tests/uniconv/test-u8-conv-to-enc.c (main): Free allocated memory. * tests/uniconv/test-u16-conv-to-enc.c (main): Likewise. * tests/uniconv/test-u32-conv-to-enc.c (main): Likewise. * tests/unistr/test-chr.h (main): Free input32. * tests/unistr/test-strchr.h (test_strchr): Likewise.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-astrxfrm.c5
-rw-r--r--tests/test-bitset.c16
-rw-r--r--tests/test-filenamecat.c1
-rw-r--r--tests/test-freadahead.c4
-rw-r--r--tests/test-freadptr.c10
-rw-r--r--tests/test-freadptr2.c1
-rw-r--r--tests/test-freadseek.c5
-rw-r--r--tests/test-gc-arcfour.c2
-rw-r--r--tests/test-gc-arctwo.c2
-rw-r--r--tests/test-gc-des.c8
-rw-r--r--tests/test-pipe-filter-gi1.c2
-rw-r--r--tests/test-pipe-filter-ii1.c2
-rw-r--r--tests/test-posix_spawn_file_actions_addchdir.c2
-rw-r--r--tests/test-posix_spawn_file_actions_addclose.c2
-rw-r--r--tests/test-posix_spawn_file_actions_adddup2.c2
-rw-r--r--tests/test-posix_spawn_file_actions_addopen.c2
-rw-r--r--tests/test-sameacls.c19
-rw-r--r--tests/test-strfmon_l.c2
-rw-r--r--tests/test-striconveh.c8
-rw-r--r--tests/uniconv/test-u16-conv-to-enc.c2
-rw-r--r--tests/uniconv/test-u32-conv-to-enc.c2
-rw-r--r--tests/uniconv/test-u8-conv-to-enc.c2
-rw-r--r--tests/unistr/test-chr.h2
-rw-r--r--tests/unistr/test-strchr.h2
24 files changed, 102 insertions, 3 deletions
diff --git a/tests/test-astrxfrm.c b/tests/test-astrxfrm.c
index c553c90362..be0241ac1f 100644
--- a/tests/test-astrxfrm.c
+++ b/tests/test-astrxfrm.c
@@ -49,6 +49,7 @@ main ()
ASSERT (transform != NULL);
ASSERT (strcmp (transform, expected_transform) == 0);
ASSERT (length == strlen (transform) + 1);
+ free (transform);
}
/* Test resultbuf != NULL with an initial length = 0. */
@@ -63,6 +64,7 @@ main ()
ASSERT (strcmp (transform, expected_transform) == 0);
ASSERT (length == strlen (transform) + 1);
ASSERT (buf[0] == '@');
+ free (transform);
}
/* Test resultbuf != NULL with an initial length that is too small. */
@@ -77,6 +79,7 @@ main ()
ASSERT (strcmp (transform, expected_transform) == 0);
ASSERT (length == strlen (transform) + 1);
ASSERT (buf[sizeof (buf) - 1] == '@');
+ free (transform);
}
/* Test resultbuf != NULL with an initial length that is large enough. */
@@ -93,5 +96,7 @@ main ()
ASSERT (buf[sizeof (buf) - 1] == '@');
}
+ free (expected_transform);
+
return 0;
}
diff --git a/tests/test-bitset.c b/tests/test-bitset.c
index a8c25316c7..032865095b 100644
--- a/tests/test-bitset.c
+++ b/tests/test-bitset.c
@@ -114,6 +114,17 @@ void compare (enum bitset_attr a, enum bitset_attr b)
ASSERT (bitset_or_and_cmp (adst, asrc0, asrc1, asrc2)
== bitset_or_and_cmp (bdst, bsrc0, bsrc1, bsrc2));
assert_bitset_equal (adst, bdst);
+
+ bitset_free (bdst);
+ bitset_free (bsrc3);
+ bitset_free (bsrc2);
+ bitset_free (bsrc1);
+ bitset_free (bsrc0);
+ bitset_free (adst);
+ bitset_free (asrc3);
+ bitset_free (asrc2);
+ bitset_free (asrc1);
+ bitset_free (asrc0);
}
void check_attributes (enum bitset_attr attr)
@@ -148,6 +159,11 @@ void check_attributes (enum bitset_attr attr)
/* or */
bitset_or (bs, bs1, bs2);
ASSERT (bitset_count (bs) == 6);
+
+ bitset_free (bs);
+ bitset_free (bs2);
+ bitset_free (bs1);
+ bitset_free (bs0);
}
int main (void)
diff --git a/tests/test-filenamecat.c b/tests/test-filenamecat.c
index 4ca7e2ffad..a37018f0c9 100644
--- a/tests/test-filenamecat.c
+++ b/tests/test-filenamecat.c
@@ -79,6 +79,7 @@ main (int argc _GL_UNUSED, char *argv[])
i, t[0], res);
fail = true;
}
+ free (res);
}
exit (fail ? EXIT_FAILURE : EXIT_SUCCESS);
}
diff --git a/tests/test-freadahead.c b/tests/test-freadahead.c
index 287a9369b8..a3c75d039c 100644
--- a/tests/test-freadahead.c
+++ b/tests/test-freadahead.c
@@ -33,6 +33,7 @@ main (int argc, char **argv)
{
void *buf = malloc (nbytes);
ASSERT (fread (buf, 1, nbytes, stdin) == nbytes);
+ free (buf);
}
if (nbytes == 0)
@@ -69,5 +70,8 @@ main (int argc, char **argv)
}
}
+ /* Free memory allocated during ungetc(). */
+ fclose (stdin);
+
return 0;
}
diff --git a/tests/test-freadptr.c b/tests/test-freadptr.c
index 8b179237b2..83b229472e 100644
--- a/tests/test-freadptr.c
+++ b/tests/test-freadptr.c
@@ -30,8 +30,11 @@ int
main (int argc, char **argv)
{
int nbytes = atoi (argv[1]);
- void *buf = malloc (nbytes);
- ASSERT (fread (buf, 1, nbytes, stdin) == nbytes);
+ {
+ void *buf = malloc (nbytes);
+ ASSERT (fread (buf, 1, nbytes, stdin) == nbytes);
+ free (buf);
+ }
if (lseek (0, 0, SEEK_CUR) == nbytes)
{
@@ -90,5 +93,8 @@ main (int argc, char **argv)
}
}
+ /* Free memory allocated during ungetc(). */
+ fclose (stdin);
+
return 0;
}
diff --git a/tests/test-freadptr2.c b/tests/test-freadptr2.c
index 95abb8d8f4..376798809c 100644
--- a/tests/test-freadptr2.c
+++ b/tests/test-freadptr2.c
@@ -43,6 +43,7 @@ main (int argc, char **argv)
{
void *buf = malloc (nbytes);
ASSERT (fread (buf, 1, nbytes, stdin) == nbytes);
+ free (buf);
}
if (nbytes == 0)
diff --git a/tests/test-freadseek.c b/tests/test-freadseek.c
index 7ae02c1e06..c5a7b4916e 100644
--- a/tests/test-freadseek.c
+++ b/tests/test-freadseek.c
@@ -89,5 +89,10 @@ main (int argc, char **argv)
ASSERT (!ferror (stdin));
#endif
+ free (buf7);
+ free (buf5);
+ free (buf3);
+ free (buf1);
+
return 0;
}
diff --git a/tests/test-gc-arcfour.c b/tests/test-gc-arcfour.c
index 6def7ab85d..aae29c9ed0 100644
--- a/tests/test-gc-arcfour.c
+++ b/tests/test-gc-arcfour.c
@@ -90,6 +90,8 @@ main (int argc, char *argv[])
return 1;
}
+ gc_cipher_close (ctx);
+
gc_done ();
return 0;
diff --git a/tests/test-gc-arctwo.c b/tests/test-gc-arctwo.c
index f52b8da1ea..647395329b 100644
--- a/tests/test-gc-arctwo.c
+++ b/tests/test-gc-arctwo.c
@@ -89,6 +89,8 @@ main (int argc, char *argv[])
return 1;
}
+ gc_cipher_close (ctx);
+
gc_done ();
return 0;
diff --git a/tests/test-gc-des.c b/tests/test-gc-des.c
index 9103d270b2..3d50f83e0d 100644
--- a/tests/test-gc-des.c
+++ b/tests/test-gc-des.c
@@ -25,7 +25,6 @@
int
main (int argc, char *argv[])
{
- gc_cipher_handle ctx;
Gc_rc rc;
rc = gc_init ();
@@ -44,9 +43,11 @@ main (int argc, char *argv[])
char input[8] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
char result[8] = { 0x24, 0x6e, 0x9d, 0xb9, 0xc5, 0x50, 0x38, 0x1a };
char temp1[8], temp2[8], temp3[8];
+ gc_cipher_handle ctx_array[64];
for (i = 0; i < 64; ++i)
{
+ gc_cipher_handle ctx;
rc = gc_cipher_open (GC_DES, GC_ECB, &ctx);
if (rc != GC_OK)
@@ -77,9 +78,14 @@ main (int argc, char *argv[])
memcpy (key, temp3, 8);
memcpy (input, temp1, 8);
+
+ ctx_array[i] = ctx;
}
if (memcmp (temp3, result, 8))
return 1;
+
+ for (i = 0; i < 64; ++i)
+ gc_cipher_close (ctx_array[i]);
}
gc_done ();
diff --git a/tests/test-pipe-filter-gi1.c b/tests/test-pipe-filter-gi1.c
index 83ce73ba12..1ba4c892ab 100644
--- a/tests/test-pipe-filter-gi1.c
+++ b/tests/test-pipe-filter-gi1.c
@@ -108,5 +108,7 @@ main (int argc, char *argv[])
ASSERT (l.nread == input_size);
}
+ free (input);
+
return 0;
}
diff --git a/tests/test-pipe-filter-ii1.c b/tests/test-pipe-filter-ii1.c
index 7efa1c2660..af97f33e8c 100644
--- a/tests/test-pipe-filter-ii1.c
+++ b/tests/test-pipe-filter-ii1.c
@@ -130,5 +130,7 @@ main (int argc, char *argv[])
ASSERT (l.nread == input_size);
}
+ free (input);
+
return 0;
}
diff --git a/tests/test-posix_spawn_file_actions_addchdir.c b/tests/test-posix_spawn_file_actions_addchdir.c
index ebdd804d2f..7a196b5d16 100644
--- a/tests/test-posix_spawn_file_actions_addchdir.c
+++ b/tests/test-posix_spawn_file_actions_addchdir.c
@@ -38,5 +38,7 @@ main (void)
ASSERT (posix_spawn_file_actions_addchdir (&actions, "/") == 0);
+ posix_spawn_file_actions_destroy (&actions);
+
return 0;
}
diff --git a/tests/test-posix_spawn_file_actions_addclose.c b/tests/test-posix_spawn_file_actions_addclose.c
index d023766ff6..77927d80ef 100644
--- a/tests/test-posix_spawn_file_actions_addclose.c
+++ b/tests/test-posix_spawn_file_actions_addclose.c
@@ -60,5 +60,7 @@ main (void)
ASSERT (posix_spawn_file_actions_addclose (&actions, bad_fd) == EBADF);
}
+ posix_spawn_file_actions_destroy (&actions);
+
return 0;
}
diff --git a/tests/test-posix_spawn_file_actions_adddup2.c b/tests/test-posix_spawn_file_actions_adddup2.c
index ebc6efd703..0c102f99cd 100644
--- a/tests/test-posix_spawn_file_actions_adddup2.c
+++ b/tests/test-posix_spawn_file_actions_adddup2.c
@@ -68,5 +68,7 @@ main (void)
ASSERT (posix_spawn_file_actions_adddup2 (&actions, 2, bad_fd) == EBADF);
}
+ posix_spawn_file_actions_destroy (&actions);
+
return 0;
}
diff --git a/tests/test-posix_spawn_file_actions_addopen.c b/tests/test-posix_spawn_file_actions_addopen.c
index abee6e885c..148002a0f6 100644
--- a/tests/test-posix_spawn_file_actions_addopen.c
+++ b/tests/test-posix_spawn_file_actions_addopen.c
@@ -66,5 +66,7 @@ main (void)
== EBADF);
}
+ posix_spawn_file_actions_destroy (&actions);
+
return 0;
}
diff --git a/tests/test-sameacls.c b/tests/test-sameacls.c
index 228c16bc35..44a111b9e1 100644
--- a/tests/test-sameacls.c
+++ b/tests/test-sameacls.c
@@ -84,6 +84,9 @@ main (int argc, char *argv[])
fflush (stderr);
abort ();
}
+
+ free (contents2);
+ free (contents1);
}
/* Compare the access permissions of the two files, including ACLs. */
@@ -218,6 +221,12 @@ main (int argc, char *argv[])
return 1;
}
}
+ acl_free (text2);
+ if (acl2 != (acl_t)NULL)
+ acl_free (acl2);
+ acl_free (text1);
+ if (acl1 != (acl_t)NULL)
+ acl_free (acl1);
}
#elif HAVE_FACL && defined GETACL /* Solaris, Cygwin, not HP-UX */
int count1;
@@ -287,6 +296,8 @@ main (int argc, char *argv[])
return 1;
}
}
+ free (entries2);
+ free (entries1);
}
# ifdef ACE_GETACL
count1 = acl (file1, ACE_GETACLCNT, 0, NULL);
@@ -366,6 +377,8 @@ main (int argc, char *argv[])
return 1;
}
}
+ free (entries2);
+ free (entries1);
}
# endif
#elif HAVE_GETACL /* HP-UX */
@@ -438,6 +451,8 @@ main (int argc, char *argv[])
return 1;
}
}
+ free (entries2);
+ free (entries1);
}
# if HAVE_ACLV_H /* HP-UX >= 11.11 */
@@ -511,6 +526,8 @@ main (int argc, char *argv[])
return 1;
}
}
+ free (entries2);
+ free (entries1);
}
# endif
#elif HAVE_ACLX_GET /* AIX */
@@ -687,6 +704,8 @@ main (int argc, char *argv[])
return 1;
}
}
+ free (entries2);
+ free (entries1);
}
#endif
}
diff --git a/tests/test-strfmon_l.c b/tests/test-strfmon_l.c
index 1294609a76..3e60b7c76f 100644
--- a/tests/test-strfmon_l.c
+++ b/tests/test-strfmon_l.c
@@ -74,6 +74,7 @@ main (void)
loc = newlocale (LC_ALL_MASK, "en_US.UTF-8", NULL);
ASSERT (strfmon_l (buf, sizeof (buf), loc, "%.2n", 123.5) >= 0);
ASSERT (strcmp (buf, expected_buf) == 0);
+ freelocale (loc);
}
{
char expected_buf[80];
@@ -86,6 +87,7 @@ main (void)
loc = newlocale (LC_ALL_MASK, "de_DE.UTF-8", NULL);
ASSERT (strfmon_l (buf, sizeof (buf), loc, "%.2n", 123.5) >= 0);
ASSERT (strcmp (buf, expected_buf) == 0);
+ freelocale (loc);
}
#endif
diff --git a/tests/test-striconveh.c b/tests/test-striconveh.c
index 6cb7f1f8cf..ed41884e78 100644
--- a/tests/test-striconveh.c
+++ b/tests/test-striconveh.c
@@ -1108,5 +1108,13 @@ main ()
#endif
+ /* -------------------------------- Done. -------------------------------- */
+
+ if (cd_ascii_to_88591 != (iconv_t)(-1))
+ iconv_close (cd_ascii_to_88591);
+ iconv_close (cd_ascii_to_utf8);
+ if (cd_utf7_to_utf8 != (iconv_t)(-1))
+ iconv_close (cd_utf7_to_utf8);
+
return 0;
}
diff --git a/tests/uniconv/test-u16-conv-to-enc.c b/tests/uniconv/test-u16-conv-to-enc.c
index 0d34816ed3..79808f6685 100644
--- a/tests/uniconv/test-u16-conv-to-enc.c
+++ b/tests/uniconv/test-u16-conv-to-enc.c
@@ -106,6 +106,8 @@ main ()
ASSERT (result == NULL);
ASSERT (errno == EILSEQ);
ASSERT (length == 0xdead);
+ if (o)
+ free (offsets);
break;
case iconveh_question_mark:
{
diff --git a/tests/uniconv/test-u32-conv-to-enc.c b/tests/uniconv/test-u32-conv-to-enc.c
index b2d48cef90..4e838a625e 100644
--- a/tests/uniconv/test-u32-conv-to-enc.c
+++ b/tests/uniconv/test-u32-conv-to-enc.c
@@ -106,6 +106,8 @@ main ()
ASSERT (result == NULL);
ASSERT (errno == EILSEQ);
ASSERT (length == 0xdead);
+ if (o)
+ free (offsets);
break;
case iconveh_question_mark:
{
diff --git a/tests/uniconv/test-u8-conv-to-enc.c b/tests/uniconv/test-u8-conv-to-enc.c
index 9e2b098915..93ec476bab 100644
--- a/tests/uniconv/test-u8-conv-to-enc.c
+++ b/tests/uniconv/test-u8-conv-to-enc.c
@@ -106,6 +106,8 @@ main ()
ASSERT (result == NULL);
ASSERT (errno == EILSEQ);
ASSERT (length == 0xdead);
+ if (o)
+ free (offsets);
break;
case iconveh_question_mark:
{
diff --git a/tests/unistr/test-chr.h b/tests/unistr/test-chr.h
index 8dbdccaf8a..375677c61a 100644
--- a/tests/unistr/test-chr.h
+++ b/tests/unistr/test-chr.h
@@ -132,6 +132,8 @@ main (void)
}
free (input);
+ if (sizeof (UNIT) != sizeof (uint32_t))
+ free (input32);
return 0;
}
diff --git a/tests/unistr/test-strchr.h b/tests/unistr/test-strchr.h
index fa48767cf9..c967b2d8c3 100644
--- a/tests/unistr/test-strchr.h
+++ b/tests/unistr/test-strchr.h
@@ -158,4 +158,6 @@ test_strchr (void)
#endif
free (input);
+ if (sizeof (UNIT) != sizeof (uint32_t))
+ free (input32);
}