gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] branch master updated: -fix memory leak in test case (#7590)


From: gnunet
Subject: [gnunet] branch master updated: -fix memory leak in test case (#7590)
Date: Tue, 17 Jan 2023 14:12:54 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new c4156bb96 -fix memory leak in test case (#7590)
c4156bb96 is described below

commit c4156bb96ce7e328a1c2cb4a9f6112818a9a11c1
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Tue Jan 17 14:12:49 2023 +0100

    -fix memory leak in test case (#7590)
---
 src/util/bio.c      |  30 +++++----
 src/util/test_bio.c | 185 +++++++++++++++++++++++++++++++---------------------
 2 files changed, 129 insertions(+), 86 deletions(-)

diff --git a/src/util/bio.c b/src/util/bio.c
index 71d0ef7fc..7e3aa0d16 100644
--- a/src/util/bio.c
+++ b/src/util/bio.c
@@ -510,13 +510,12 @@ GNUNET_BIO_write_open_file (const char *fn)
   struct GNUNET_DISK_FileHandle *fd;
   struct GNUNET_BIO_WriteHandle *h;
 
-  fd =
-    GNUNET_DISK_file_open (fn,
-                           GNUNET_DISK_OPEN_WRITE
-                           | GNUNET_DISK_OPEN_TRUNCATE
-                           | GNUNET_DISK_OPEN_CREATE,
-                           GNUNET_DISK_PERM_USER_READ
-                           | GNUNET_DISK_PERM_USER_WRITE);
+  fd = GNUNET_DISK_file_open (fn,
+                              GNUNET_DISK_OPEN_WRITE
+                              | GNUNET_DISK_OPEN_TRUNCATE
+                              | GNUNET_DISK_OPEN_CREATE,
+                              GNUNET_DISK_PERM_USER_READ
+                              | GNUNET_DISK_PERM_USER_WRITE);
   if (NULL == fd)
     return NULL;
   h = GNUNET_malloc (sizeof(struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE);
@@ -611,14 +610,16 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h)
 
   if (IO_FILE != h->type)
     return GNUNET_OK;
-
-  ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->have);
+  ret = GNUNET_DISK_file_write (h->fd,
+                                h->buffer,
+                                h->have);
   if (ret != (ssize_t) h->have)
   {
     GNUNET_DISK_file_close (h->fd);
     h->fd = NULL;
     GNUNET_free (h->emsg);
-    GNUNET_asprintf (&h->emsg, _ ("Unable to flush buffer to file"));
+    GNUNET_asprintf (&h->emsg,
+                     "Unable to flush buffer to file");
     return GNUNET_SYSERR;
   }
   h->have = 0;
@@ -638,7 +639,7 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h)
  * @param size where to store the size of @e contents
  * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
  */
-int
+enum GNUNET_GenericReturnValue
 GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h,
                                 char **emsg,
                                 void **contents,
@@ -648,7 +649,10 @@ GNUNET_BIO_get_buffer_contents (struct 
GNUNET_BIO_WriteHandle *h,
     return GNUNET_SYSERR;
   if ((NULL == contents) || (NULL == size))
     return GNUNET_SYSERR;
-  int ret = (NULL != h->emsg) ? GNUNET_SYSERR : GNUNET_OK;
+  enum GNUNET_GenericReturnValue ret
+    = (NULL != h->emsg)
+    ? GNUNET_SYSERR
+    : GNUNET_OK;
   if (NULL != emsg)
     *emsg = h->emsg;
   else
@@ -667,7 +671,7 @@ GNUNET_BIO_get_buffer_contents (struct 
GNUNET_BIO_WriteHandle *h,
  * @param len the number of bytes to write
  * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
  */
-static int
+static enum GNUNET_GenericReturnValue
 write_to_file (struct GNUNET_BIO_WriteHandle *h,
                const char *what,
                const char *source,
diff --git a/src/util/test_bio.c b/src/util/test_bio.c
index 950dd1142..b407eccfe 100644
--- a/src/util/test_bio.c
+++ b/src/util/test_bio.c
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2009 GNUnet e.V.
+     Copyright (C) 2009, 2023 GNUnet e.V.
 
      GNUnet is free software: you can redistribute it and/or modify it
      under the terms of the GNU Affero General Public License as published
@@ -17,14 +17,11 @@
 
      SPDX-License-Identifier: AGPL3.0-or-later
  */
-
 /**
  * @file util/test_bio.c
  * @brief testcase for the buffered IO module
  * @author Ji Lu
  */
-
-
 #include "platform.h"
 #include "gnunet_util_lib.h"
 #define TESTSTRING "testString"
@@ -42,24 +39,29 @@ test_normal_rw (void)
   char *rString = NULL;
   int64_t wNum = TESTNUMBER64;
   int64_t rNum = 0;
-
   struct GNUNET_BIO_WriteSpec ws[] = {
-    GNUNET_BIO_write_spec_string ("test-normal-rw-string", TESTSTRING),
-    GNUNET_BIO_write_spec_int64 ("test-normal-rw-int64", &wNum),
+    GNUNET_BIO_write_spec_string ("test-normal-rw-string",
+                                  TESTSTRING),
+    GNUNET_BIO_write_spec_int64 ("test-normal-rw-int64",
+                                 &wNum),
     GNUNET_BIO_write_spec_end (),
   };
-
   struct GNUNET_BIO_ReadSpec rs[] = {
-    GNUNET_BIO_read_spec_string ("test-normal-rw-string", &rString, 200),
-    GNUNET_BIO_read_spec_int64 ("test-normal-rw-int64", &rNum),
+    GNUNET_BIO_read_spec_string ("test-normal-rw-string",
+                                 &rString,
+                                 200),
+    GNUNET_BIO_read_spec_int64 ("test-normal-rw-int64",
+                                &rNum),
     GNUNET_BIO_read_spec_end (),
   };
 
   /* I/O on file */
   wh = GNUNET_BIO_write_open_file (filename);
   GNUNET_assert (NULL != wh);
-  GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_spec_commit (wh, ws));
-  GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL));
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_BIO_write_spec_commit (wh, ws));
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_BIO_write_close (wh, NULL));
 
   rh = GNUNET_BIO_read_open_file (filename);
   GNUNET_assert (NULL != rh);
@@ -72,26 +74,37 @@ test_normal_rw (void)
   GNUNET_assert (0 == strcmp (TESTSTRING,
                               rString));
   GNUNET_assert (wNum == rNum);
-
-  GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename));
+  GNUNET_free (rString);
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_DISK_directory_remove (filename));
   GNUNET_free (filename);
 
   /* I/O on buffer */
   wh = GNUNET_BIO_write_open_buffer ();
   GNUNET_assert (NULL != wh);
-  GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_spec_commit (wh, ws));
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_BIO_write_spec_commit (wh,
+                                               ws));
   GNUNET_assert (GNUNET_OK ==
                  GNUNET_BIO_get_buffer_contents (wh,
                                                  NULL,
                                                  &buffer,
                                                  &buffer_size));
-  GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL));
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_BIO_write_close (wh,
+                                         NULL));
 
-  rh = GNUNET_BIO_read_open_buffer (buffer, buffer_size);
+  rh = GNUNET_BIO_read_open_buffer (buffer,
+                                    buffer_size);
   GNUNET_assert (NULL != rh);
-  GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_spec_commit (rh, rs));
-  GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL));
-  GNUNET_assert (0 == strcmp (TESTSTRING, rString));
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_BIO_read_spec_commit (rh,
+                                              rs));
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_BIO_read_close (rh,
+                                        NULL));
+  GNUNET_assert (0 == strcmp (TESTSTRING,
+                              rString));
   GNUNET_assert (wNum == rNum);
   GNUNET_free (rString);
   GNUNET_free (buffer);
@@ -110,21 +123,26 @@ test_nullstring_rw (void)
 
   wh = GNUNET_BIO_write_open_file (filename);
   GNUNET_assert (NULL != wh);
-  GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (wh,
-                                                       "test-nullstring-rw",
-                                                       NULL));
-  GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL));
-
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_BIO_write_string (wh,
+                                          "test-nullstring-rw",
+                                          NULL));
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_BIO_write_close (wh,
+                                         NULL));
   rh = GNUNET_BIO_read_open_file (filename);
   GNUNET_assert (NULL != rh);
-  GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_string (rh,
-                                                      "test-nullstring-rw",
-                                                      &rString, 200));
-  GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL));
-
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_BIO_read_string (rh,
+                                         "test-nullstring-rw",
+                                         &rString,
+                                         200));
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_BIO_read_close (rh,
+                                        NULL));
   GNUNET_assert (NULL == rString);
-
-  GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename));
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_DISK_directory_remove (filename));
   GNUNET_free (filename);
   return 0;
 }
@@ -140,21 +158,26 @@ test_emptystring_rw (void)
 
   wh = GNUNET_BIO_write_open_file (filename);
   GNUNET_assert (NULL != wh);
-  GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (wh,
-                                                       "test-emptystring-rw",
-                                                       ""));
-  GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL));
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_BIO_write_string (wh,
+                                          "test-emptystring-rw",
+                                          ""));
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_BIO_write_close (wh,
+                                         NULL));
 
   rh = GNUNET_BIO_read_open_file (filename);
   GNUNET_assert (NULL != rh);
-  GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_string (rh,
-                                                      "test-emptystring-rw",
-                                                      &rString, 200));
-  GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL));
-
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_BIO_read_string (rh,
+                                         "test-emptystring-rw",
+                                         &rString, 200));
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_BIO_read_close (rh,
+                                        NULL));
   GNUNET_free (rString);
-
-  GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename));
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_DISK_directory_remove (filename));
   GNUNET_free (filename);
   return 0;
 }
@@ -170,21 +193,25 @@ test_bigstring_rw (void)
 
   wh = GNUNET_BIO_write_open_file (filename);
   GNUNET_assert (NULL != wh);
-  GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (wh,
-                                                       "test-bigstring-rw",
-                                                       TESTSTRING));
-  GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL));
-
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_BIO_write_string (wh,
+                                          "test-bigstring-rw",
+                                          TESTSTRING));
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_BIO_write_close (wh,
+                                         NULL));
   rh = GNUNET_BIO_read_open_file (filename);
   GNUNET_assert (NULL != rh);
-  GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_string (rh,
-                                                          "test-bigstring-rw",
-                                                          &rString, 1));
-  GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL));
-
+  GNUNET_assert (GNUNET_SYSERR ==
+                 GNUNET_BIO_read_string (rh,
+                                         "test-bigstring-rw",
+                                         &rString, 1));
+  GNUNET_assert (GNUNET_SYSERR ==
+                 GNUNET_BIO_read_close (rh,
+                                        NULL));
   GNUNET_assert (NULL == rString);
-
-  GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename));
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_DISK_directory_remove (filename));
   GNUNET_free (filename);
   return 0;
 }
@@ -199,11 +226,14 @@ test_directory_r (void)
 
   rh = GNUNET_BIO_read_open_file ("/dev");
   GNUNET_assert (NULL != rh);
-  GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read (rh,
-                                                   "test-directory-r",
-                                                   rString,
-                                                   sizeof (rString)));
-  GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL));
+  GNUNET_assert (GNUNET_SYSERR ==
+                 GNUNET_BIO_read (rh,
+                                  "test-directory-r",
+                                  rString,
+                                  sizeof (rString)));
+  GNUNET_assert (GNUNET_SYSERR ==
+                 GNUNET_BIO_read_close (rh,
+                                        NULL));
 #endif
   return 0;
 }
@@ -264,13 +294,17 @@ test_fullfile_rw (void)
 
   wh = GNUNET_BIO_write_open_file ("/dev/full");
   GNUNET_assert (NULL != wh);
-  GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_write_spec_commit (wh, ws));
-  GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_write_close (wh, NULL));
+  GNUNET_assert (GNUNET_SYSERR ==
+                 GNUNET_BIO_write_spec_commit (wh, ws));
+  GNUNET_assert (GNUNET_SYSERR ==
+                 GNUNET_BIO_write_close (wh, NULL));
 
   rh = GNUNET_BIO_read_open_file ("/dev/null");
   GNUNET_assert (NULL != rh);
-  GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_spec_commit (rh, rs));
-  GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL));
+  GNUNET_assert (GNUNET_SYSERR ==
+                 GNUNET_BIO_read_spec_commit (rh, rs));
+  GNUNET_assert (GNUNET_SYSERR ==
+                 GNUNET_BIO_read_close (rh, NULL));
 
   GNUNET_assert (NULL == rString);
 #endif
@@ -288,22 +322,27 @@ test_fakestring_rw (void)
 
   wh = GNUNET_BIO_write_open_file (filename);
   GNUNET_assert (NULL != wh);
-  GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (wh,
-                                                      
"test-fakestring-rw-int32",
-                                                      2));
-  GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL));
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_BIO_write_int32 (wh,
+                                         "test-fakestring-rw-int32",
+                                         2));
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_BIO_write_close (wh,
+                                         NULL));
 
   rh = GNUNET_BIO_read_open_file (filename);
   GNUNET_assert (NULL != rh);
   GNUNET_assert (GNUNET_SYSERR ==
                  GNUNET_BIO_read_string (rh,
                                          "test-fakestring-rw-string",
-                                         &rString, 200));
-  GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL));
-
+                                         &rString,
+                                         200));
+  GNUNET_assert (GNUNET_SYSERR ==
+                 GNUNET_BIO_read_close (rh,
+                                        NULL));
   GNUNET_assert (NULL == rString);
-
-  GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename));
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_DISK_directory_remove (filename));
   GNUNET_free (filename);
   return 0;
 }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]