# HG changeset patch # User Bruno Haible # Date 1552223109 -3600 # Node ID 5d9b82ca550ac4385eb49bda930f40857aba4d23 # Parent 84a15f7137a7e52431e3af14c36dbe0bfa7986a9 tests: Free allocated memory. Reported by 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. diff -r 84a15f7137a7 -r 5d9b82ca550a ChangeLog --- a/ChangeLog Sun Mar 10 13:08:25 2019 +0100 +++ b/ChangeLog Sun Mar 10 14:05:09 2019 +0100 @@ -1,3 +1,34 @@ +2019-03-10 Bruno Haible + + tests: Free allocated memory. + Reported by 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. + 2019-03-10 Bruno Haible tests: Prepare for using valgrind. diff -r 84a15f7137a7 -r 5d9b82ca550a tests/test-astrxfrm.c --- a/tests/test-astrxfrm.c Sun Mar 10 13:08:25 2019 +0100 +++ b/tests/test-astrxfrm.c Sun Mar 10 14:05:09 2019 +0100 @@ -49,6 +49,7 @@ 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 @@ 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 @@ 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 @@ ASSERT (buf[sizeof (buf) - 1] == '@'); } + free (expected_transform); + return 0; } diff -r 84a15f7137a7 -r 5d9b82ca550a tests/test-bitset.c --- a/tests/test-bitset.c Sun Mar 10 13:08:25 2019 +0100 +++ b/tests/test-bitset.c Sun Mar 10 14:05:09 2019 +0100 @@ -114,6 +114,17 @@ 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 @@ /* 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 -r 84a15f7137a7 -r 5d9b82ca550a tests/test-filenamecat.c --- a/tests/test-filenamecat.c Sun Mar 10 13:08:25 2019 +0100 +++ b/tests/test-filenamecat.c Sun Mar 10 14:05:09 2019 +0100 @@ -79,6 +79,7 @@ i, t[0], res); fail = true; } + free (res); } exit (fail ? EXIT_FAILURE : EXIT_SUCCESS); } diff -r 84a15f7137a7 -r 5d9b82ca550a tests/test-freadahead.c --- a/tests/test-freadahead.c Sun Mar 10 13:08:25 2019 +0100 +++ b/tests/test-freadahead.c Sun Mar 10 14:05:09 2019 +0100 @@ -33,6 +33,7 @@ { void *buf = malloc (nbytes); ASSERT (fread (buf, 1, nbytes, stdin) == nbytes); + free (buf); } if (nbytes == 0) @@ -69,5 +70,8 @@ } } + /* Free memory allocated during ungetc(). */ + fclose (stdin); + return 0; } diff -r 84a15f7137a7 -r 5d9b82ca550a tests/test-freadptr.c --- a/tests/test-freadptr.c Sun Mar 10 13:08:25 2019 +0100 +++ b/tests/test-freadptr.c Sun Mar 10 14:05:09 2019 +0100 @@ -30,8 +30,11 @@ 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 @@ } } + /* Free memory allocated during ungetc(). */ + fclose (stdin); + return 0; } diff -r 84a15f7137a7 -r 5d9b82ca550a tests/test-freadptr2.c --- a/tests/test-freadptr2.c Sun Mar 10 13:08:25 2019 +0100 +++ b/tests/test-freadptr2.c Sun Mar 10 14:05:09 2019 +0100 @@ -43,6 +43,7 @@ { void *buf = malloc (nbytes); ASSERT (fread (buf, 1, nbytes, stdin) == nbytes); + free (buf); } if (nbytes == 0) diff -r 84a15f7137a7 -r 5d9b82ca550a tests/test-freadseek.c --- a/tests/test-freadseek.c Sun Mar 10 13:08:25 2019 +0100 +++ b/tests/test-freadseek.c Sun Mar 10 14:05:09 2019 +0100 @@ -89,5 +89,10 @@ ASSERT (!ferror (stdin)); #endif + free (buf7); + free (buf5); + free (buf3); + free (buf1); + return 0; } diff -r 84a15f7137a7 -r 5d9b82ca550a tests/test-gc-arcfour.c --- a/tests/test-gc-arcfour.c Sun Mar 10 13:08:25 2019 +0100 +++ b/tests/test-gc-arcfour.c Sun Mar 10 14:05:09 2019 +0100 @@ -90,6 +90,8 @@ return 1; } + gc_cipher_close (ctx); + gc_done (); return 0; diff -r 84a15f7137a7 -r 5d9b82ca550a tests/test-gc-arctwo.c --- a/tests/test-gc-arctwo.c Sun Mar 10 13:08:25 2019 +0100 +++ b/tests/test-gc-arctwo.c Sun Mar 10 14:05:09 2019 +0100 @@ -89,6 +89,8 @@ return 1; } + gc_cipher_close (ctx); + gc_done (); return 0; diff -r 84a15f7137a7 -r 5d9b82ca550a tests/test-gc-des.c --- a/tests/test-gc-des.c Sun Mar 10 13:08:25 2019 +0100 +++ b/tests/test-gc-des.c Sun Mar 10 14:05:09 2019 +0100 @@ -25,7 +25,6 @@ int main (int argc, char *argv[]) { - gc_cipher_handle ctx; Gc_rc rc; rc = gc_init (); @@ -44,9 +43,11 @@ 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 @@ 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 -r 84a15f7137a7 -r 5d9b82ca550a tests/test-pipe-filter-gi1.c --- a/tests/test-pipe-filter-gi1.c Sun Mar 10 13:08:25 2019 +0100 +++ b/tests/test-pipe-filter-gi1.c Sun Mar 10 14:05:09 2019 +0100 @@ -108,5 +108,7 @@ ASSERT (l.nread == input_size); } + free (input); + return 0; } diff -r 84a15f7137a7 -r 5d9b82ca550a tests/test-pipe-filter-ii1.c --- a/tests/test-pipe-filter-ii1.c Sun Mar 10 13:08:25 2019 +0100 +++ b/tests/test-pipe-filter-ii1.c Sun Mar 10 14:05:09 2019 +0100 @@ -130,5 +130,7 @@ ASSERT (l.nread == input_size); } + free (input); + return 0; } diff -r 84a15f7137a7 -r 5d9b82ca550a tests/test-posix_spawn_file_actions_addchdir.c --- a/tests/test-posix_spawn_file_actions_addchdir.c Sun Mar 10 13:08:25 2019 +0100 +++ b/tests/test-posix_spawn_file_actions_addchdir.c Sun Mar 10 14:05:09 2019 +0100 @@ -38,5 +38,7 @@ ASSERT (posix_spawn_file_actions_addchdir (&actions, "/") == 0); + posix_spawn_file_actions_destroy (&actions); + return 0; } diff -r 84a15f7137a7 -r 5d9b82ca550a tests/test-posix_spawn_file_actions_addclose.c --- a/tests/test-posix_spawn_file_actions_addclose.c Sun Mar 10 13:08:25 2019 +0100 +++ b/tests/test-posix_spawn_file_actions_addclose.c Sun Mar 10 14:05:09 2019 +0100 @@ -60,5 +60,7 @@ ASSERT (posix_spawn_file_actions_addclose (&actions, bad_fd) == EBADF); } + posix_spawn_file_actions_destroy (&actions); + return 0; } diff -r 84a15f7137a7 -r 5d9b82ca550a tests/test-posix_spawn_file_actions_adddup2.c --- a/tests/test-posix_spawn_file_actions_adddup2.c Sun Mar 10 13:08:25 2019 +0100 +++ b/tests/test-posix_spawn_file_actions_adddup2.c Sun Mar 10 14:05:09 2019 +0100 @@ -68,5 +68,7 @@ ASSERT (posix_spawn_file_actions_adddup2 (&actions, 2, bad_fd) == EBADF); } + posix_spawn_file_actions_destroy (&actions); + return 0; } diff -r 84a15f7137a7 -r 5d9b82ca550a tests/test-posix_spawn_file_actions_addopen.c --- a/tests/test-posix_spawn_file_actions_addopen.c Sun Mar 10 13:08:25 2019 +0100 +++ b/tests/test-posix_spawn_file_actions_addopen.c Sun Mar 10 14:05:09 2019 +0100 @@ -66,5 +66,7 @@ == EBADF); } + posix_spawn_file_actions_destroy (&actions); + return 0; } diff -r 84a15f7137a7 -r 5d9b82ca550a tests/test-sameacls.c --- a/tests/test-sameacls.c Sun Mar 10 13:08:25 2019 +0100 +++ b/tests/test-sameacls.c Sun Mar 10 14:05:09 2019 +0100 @@ -84,6 +84,9 @@ fflush (stderr); abort (); } + + free (contents2); + free (contents1); } /* Compare the access permissions of the two files, including ACLs. */ @@ -218,6 +221,12 @@ 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 @@ return 1; } } + free (entries2); + free (entries1); } # ifdef ACE_GETACL count1 = acl (file1, ACE_GETACLCNT, 0, NULL); @@ -366,6 +377,8 @@ return 1; } } + free (entries2); + free (entries1); } # endif #elif HAVE_GETACL /* HP-UX */ @@ -438,6 +451,8 @@ return 1; } } + free (entries2); + free (entries1); } # if HAVE_ACLV_H /* HP-UX >= 11.11 */ @@ -511,6 +526,8 @@ return 1; } } + free (entries2); + free (entries1); } # endif #elif HAVE_ACLX_GET /* AIX */ @@ -687,6 +704,8 @@ return 1; } } + free (entries2); + free (entries1); } #endif } diff -r 84a15f7137a7 -r 5d9b82ca550a tests/test-strfmon_l.c --- a/tests/test-strfmon_l.c Sun Mar 10 13:08:25 2019 +0100 +++ b/tests/test-strfmon_l.c Sun Mar 10 14:05:09 2019 +0100 @@ -74,6 +74,7 @@ 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 @@ 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 -r 84a15f7137a7 -r 5d9b82ca550a tests/test-striconveh.c --- a/tests/test-striconveh.c Sun Mar 10 13:08:25 2019 +0100 +++ b/tests/test-striconveh.c Sun Mar 10 14:05:09 2019 +0100 @@ -1108,5 +1108,13 @@ #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 -r 84a15f7137a7 -r 5d9b82ca550a tests/uniconv/test-u16-conv-to-enc.c --- a/tests/uniconv/test-u16-conv-to-enc.c Sun Mar 10 13:08:25 2019 +0100 +++ b/tests/uniconv/test-u16-conv-to-enc.c Sun Mar 10 14:05:09 2019 +0100 @@ -106,6 +106,8 @@ ASSERT (result == NULL); ASSERT (errno == EILSEQ); ASSERT (length == 0xdead); + if (o) + free (offsets); break; case iconveh_question_mark: { diff -r 84a15f7137a7 -r 5d9b82ca550a tests/uniconv/test-u32-conv-to-enc.c --- a/tests/uniconv/test-u32-conv-to-enc.c Sun Mar 10 13:08:25 2019 +0100 +++ b/tests/uniconv/test-u32-conv-to-enc.c Sun Mar 10 14:05:09 2019 +0100 @@ -106,6 +106,8 @@ ASSERT (result == NULL); ASSERT (errno == EILSEQ); ASSERT (length == 0xdead); + if (o) + free (offsets); break; case iconveh_question_mark: { diff -r 84a15f7137a7 -r 5d9b82ca550a tests/uniconv/test-u8-conv-to-enc.c --- a/tests/uniconv/test-u8-conv-to-enc.c Sun Mar 10 13:08:25 2019 +0100 +++ b/tests/uniconv/test-u8-conv-to-enc.c Sun Mar 10 14:05:09 2019 +0100 @@ -106,6 +106,8 @@ ASSERT (result == NULL); ASSERT (errno == EILSEQ); ASSERT (length == 0xdead); + if (o) + free (offsets); break; case iconveh_question_mark: { diff -r 84a15f7137a7 -r 5d9b82ca550a tests/unistr/test-chr.h --- a/tests/unistr/test-chr.h Sun Mar 10 13:08:25 2019 +0100 +++ b/tests/unistr/test-chr.h Sun Mar 10 14:05:09 2019 +0100 @@ -132,6 +132,8 @@ } free (input); + if (sizeof (UNIT) != sizeof (uint32_t)) + free (input32); return 0; } diff -r 84a15f7137a7 -r 5d9b82ca550a tests/unistr/test-strchr.h --- a/tests/unistr/test-strchr.h Sun Mar 10 13:08:25 2019 +0100 +++ b/tests/unistr/test-strchr.h Sun Mar 10 14:05:09 2019 +0100 @@ -158,4 +158,6 @@ #endif free (input); + if (sizeof (UNIT) != sizeof (uint32_t)) + free (input32); }