]> Savannah Git Hosting - gnulib.git/commitdiff
tests: Free allocated memory.
authorBruno Haible <bruno@clisp.org>
Sun, 10 Mar 2019 13:05:09 +0000 (14:05 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 10 Mar 2019 13:05:09 +0000 (14:05 +0100)
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.

25 files changed:
ChangeLog
tests/test-astrxfrm.c
tests/test-bitset.c
tests/test-filenamecat.c
tests/test-freadahead.c
tests/test-freadptr.c
tests/test-freadptr2.c
tests/test-freadseek.c
tests/test-gc-arcfour.c
tests/test-gc-arctwo.c
tests/test-gc-des.c
tests/test-pipe-filter-gi1.c
tests/test-pipe-filter-ii1.c
tests/test-posix_spawn_file_actions_addchdir.c
tests/test-posix_spawn_file_actions_addclose.c
tests/test-posix_spawn_file_actions_adddup2.c
tests/test-posix_spawn_file_actions_addopen.c
tests/test-sameacls.c
tests/test-strfmon_l.c
tests/test-striconveh.c
tests/uniconv/test-u16-conv-to-enc.c
tests/uniconv/test-u32-conv-to-enc.c
tests/uniconv/test-u8-conv-to-enc.c
tests/unistr/test-chr.h
tests/unistr/test-strchr.h

index 977908d68e12fd31c3bd8bf8d84286148fd28e63..a5f2a6150c985a09db13b6a74a2b2108ba51e027 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,34 @@
+2019-03-10  Bruno Haible  <bruno@clisp.org>
+
+       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.
+
 2019-03-10  Bruno Haible  <bruno@clisp.org>
 
        tests: Prepare for using valgrind.
index c553c903626a11389fd19fd27e83935c6624ba10..be0241ac1f8bf03fc158c1d847759924249da576 100644 (file)
@@ -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;
 }
index a8c25316c752e5428b797aa09232918f535806e1..032865095b5732aa2bd3ec00d32b89836cfae8a7 100644 (file)
@@ -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)
index 4ca7e2ffad30c8d6982b290bed8448e3a7b2742a..a37018f0c9e00199b546eb46c6aa1241f654effe 100644 (file)
@@ -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);
 }
index 287a9369b8ccbb70d5905539f5b83dac6eba64a4..a3c75d039c2c5cadf3f7657301d2e5248a95e991 100644 (file)
@@ -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;
 }
index 8b179237b21b49594a21da588a83dfae46f0cd33..83b229472e7b12aae242b0e23b902b9ab39c21b5 100644 (file)
@@ -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;
 }
index 95abb8d8f42a073e4ca4192935c45a0936809108..376798809cc762c2976dde82960a8a3a6bc4c9f5 100644 (file)
@@ -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)
index 7ae02c1e0680d5ee4006ccc21a14c29669cd1842..c5a7b4916e82bf26a777398eaf47f1e9eb9b630a 100644 (file)
@@ -89,5 +89,10 @@ main (int argc, char **argv)
   ASSERT (!ferror (stdin));
 #endif
 
+  free (buf7);
+  free (buf5);
+  free (buf3);
+  free (buf1);
+
   return 0;
 }
index 6def7ab85d094065fb951a6f08c6f21a7aae8109..aae29c9ed0328f7469a206b3fc2dd2db7ce6d0a1 100644 (file)
@@ -90,6 +90,8 @@ main (int argc, char *argv[])
       return 1;
     }
 
+  gc_cipher_close (ctx);
+
   gc_done ();
 
   return 0;
index f52b8da1ea3a26af36b94f8c291cf79c5209e743..647395329b5c86f89574362c06d6eb07605cfb95 100644 (file)
@@ -89,6 +89,8 @@ main (int argc, char *argv[])
       return 1;
     }
 
+  gc_cipher_close (ctx);
+
   gc_done ();
 
   return 0;
index 9103d270b28b4c63234190c2428e4438c2569dbb..3d50f83e0d79ee254e33f27de0eb24f272b7044d 100644 (file)
@@ -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 ();
index 83ce73ba12c3dd877041a08efaa877ac296ad3bc..1ba4c892ab7d7dbc757b64528868e5af7cab95f6 100644 (file)
@@ -108,5 +108,7 @@ main (int argc, char *argv[])
     ASSERT (l.nread == input_size);
   }
 
+  free (input);
+
   return 0;
 }
index 7efa1c26607de92af4735b4ecd3748c45a69dd45..af97f33e8c2a405152b5588381a33a803538e2eb 100644 (file)
@@ -130,5 +130,7 @@ main (int argc, char *argv[])
     ASSERT (l.nread == input_size);
   }
 
+  free (input);
+
   return 0;
 }
index ebdd804d2f92179e3c77efb7703f9d3e38dc21dc..7a196b5d16c8d5a4a6fd40b783e31fd7f667de9b 100644 (file)
@@ -38,5 +38,7 @@ main (void)
 
   ASSERT (posix_spawn_file_actions_addchdir (&actions, "/") == 0);
 
+  posix_spawn_file_actions_destroy (&actions);
+
   return 0;
 }
index d023766ff62af83569611f6d402a4a1deeef176d..77927d80eff90c9ea8a1391aa5895ba3f17eaf20 100644 (file)
@@ -60,5 +60,7 @@ main (void)
     ASSERT (posix_spawn_file_actions_addclose (&actions, bad_fd) == EBADF);
   }
 
+  posix_spawn_file_actions_destroy (&actions);
+
   return 0;
 }
index ebc6efd7032d86f316a22216d5e234ebb109f92b..0c102f99cd222ccd0f8eb203e982d11c88fe2585 100644 (file)
@@ -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;
 }
index abee6e885c7647d574bd1313f16aded14bcc1c7d..148002a0f6965af91b8a9362b39f65ac9b3dd7c4 100644 (file)
@@ -66,5 +66,7 @@ main (void)
             == EBADF);
   }
 
+  posix_spawn_file_actions_destroy (&actions);
+
   return 0;
 }
index 228c16bc359028b4920f96bbd55ddb59fefc9d62..44a111b9e13e1f03f1f5e9750c50005134c29d9d 100644 (file)
@@ -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
   }
index 1294609a764292f5f38efbd3599a1dd11e433ecf..3e60b7c76f49a80888e9bf2ba112f31c091e5811 100644 (file)
@@ -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
 
index 6cb7f1f8cfc5b47cf949cf0853d28e24600404e7..ed41884e7852cd4ac11bbb5e58f5a0d5b34deebf 100644 (file)
@@ -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;
 }
index 0d34816ed3ed78e8808ad3c5fdc143366d1237d4..79808f6685f1108c5f11b2430adb34b01da0b383 100644 (file)
@@ -106,6 +106,8 @@ main ()
               ASSERT (result == NULL);
               ASSERT (errno == EILSEQ);
               ASSERT (length == 0xdead);
+              if (o)
+                free (offsets);
               break;
             case iconveh_question_mark:
               {
index b2d48cef90a157ec1500feb42353c38ec7518abf..4e838a625e6168204e262dc127888a7da9effa48 100644 (file)
@@ -106,6 +106,8 @@ main ()
               ASSERT (result == NULL);
               ASSERT (errno == EILSEQ);
               ASSERT (length == 0xdead);
+              if (o)
+                free (offsets);
               break;
             case iconveh_question_mark:
               {
index 9e2b09891510fed88ad767f1a3d21836184aab2f..93ec476bab63f6fff44dc619112fa50c329c1513 100644 (file)
@@ -106,6 +106,8 @@ main ()
               ASSERT (result == NULL);
               ASSERT (errno == EILSEQ);
               ASSERT (length == 0xdead);
+              if (o)
+                free (offsets);
               break;
             case iconveh_question_mark:
               {
index 8dbdccaf8aaf710e173d9c41d88c964158db2ddb..375677c61a2b9abf53a5c11187545d2702dbf72d 100644 (file)
@@ -132,6 +132,8 @@ main (void)
   }
 
   free (input);
+  if (sizeof (UNIT) != sizeof (uint32_t))
+    free (input32);
 
   return 0;
 }
index fa48767cf9a998ed8200b83e8dcfc26f5a883520..c967b2d8c332fc02cbfdd680b853212080db411a 100644 (file)
@@ -158,4 +158,6 @@ test_strchr (void)
 #endif
 
   free (input);
+  if (sizeof (UNIT) != sizeof (uint32_t))
+    free (input32);
 }