diff options
author | Christian Grothoff <christian@grothoff.org> | 2023-01-16 09:35:35 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2023-01-16 09:35:45 +0100 |
commit | 31dcac7e27e676a3bd00b8359806cb598d10696a (patch) | |
tree | 4acf4ba1ea34ffe596270bf50ca34bb32d832118 /src/util | |
parent | 6ebbb6fecbda09436265df7525367cba943b0c07 (diff) | |
download | gnunet-31dcac7e27e676a3bd00b8359806cb598d10696a.tar.gz gnunet-31dcac7e27e676a3bd00b8359806cb598d10696a.zip |
bio: fix memory leak (#7590)
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/bio.c | 17 | ||||
-rw-r--r-- | src/util/test_bio.c | 14 |
2 files changed, 19 insertions, 12 deletions
diff --git a/src/util/bio.c b/src/util/bio.c index 70620aea7..71d0ef7fc 100644 --- a/src/util/bio.c +++ b/src/util/bio.c | |||
@@ -182,8 +182,9 @@ GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg) | |||
182 | return err; | 182 | return err; |
183 | } | 183 | } |
184 | 184 | ||
185 | |||
185 | void | 186 | void |
186 | GNUNET_BIO_read_set_error (struct GNUNET_BIO_ReadHandle *h, const char* emsg) | 187 | GNUNET_BIO_read_set_error (struct GNUNET_BIO_ReadHandle *h, const char*emsg) |
187 | { | 188 | { |
188 | GNUNET_assert (NULL == h->emsg); | 189 | GNUNET_assert (NULL == h->emsg); |
189 | h->emsg = GNUNET_strdup (emsg); | 190 | h->emsg = GNUNET_strdup (emsg); |
@@ -380,7 +381,6 @@ GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, | |||
380 | } | 381 | } |
381 | 382 | ||
382 | 383 | ||
383 | |||
384 | /** | 384 | /** |
385 | * Read a float. | 385 | * Read a float. |
386 | * | 386 | * |
@@ -553,8 +553,9 @@ GNUNET_BIO_write_open_buffer (void) | |||
553 | * if the handle has an error message, the return value is #GNUNET_SYSERR | 553 | * if the handle has an error message, the return value is #GNUNET_SYSERR |
554 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 554 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
555 | */ | 555 | */ |
556 | int | 556 | enum GNUNET_GenericReturnValue |
557 | GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg) | 557 | GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, |
558 | char **emsg) | ||
558 | { | 559 | { |
559 | int err; | 560 | int err; |
560 | 561 | ||
@@ -567,7 +568,10 @@ GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg) | |||
567 | { | 568 | { |
568 | case IO_FILE: | 569 | case IO_FILE: |
569 | if (NULL == h->fd) | 570 | if (NULL == h->fd) |
570 | return GNUNET_SYSERR; | 571 | { |
572 | err = GNUNET_SYSERR; | ||
573 | break; | ||
574 | } | ||
571 | if (GNUNET_OK != GNUNET_BIO_flush (h)) | 575 | if (GNUNET_OK != GNUNET_BIO_flush (h)) |
572 | { | 576 | { |
573 | if (NULL != emsg) | 577 | if (NULL != emsg) |
@@ -600,7 +604,7 @@ GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg) | |||
600 | * @return #GNUNET_OK upon success. Upon failure #GNUNET_SYSERR is returned | 604 | * @return #GNUNET_OK upon success. Upon failure #GNUNET_SYSERR is returned |
601 | * and the file is closed | 605 | * and the file is closed |
602 | */ | 606 | */ |
603 | int | 607 | enum GNUNET_GenericReturnValue |
604 | GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h) | 608 | GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h) |
605 | { | 609 | { |
606 | ssize_t ret; | 610 | ssize_t ret; |
@@ -793,7 +797,6 @@ GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, | |||
793 | } | 797 | } |
794 | 798 | ||
795 | 799 | ||
796 | |||
797 | /** | 800 | /** |
798 | * Write a float. | 801 | * Write a float. |
799 | * | 802 | * |
diff --git a/src/util/test_bio.c b/src/util/test_bio.c index 90f0121d4..950dd1142 100644 --- a/src/util/test_bio.c +++ b/src/util/test_bio.c | |||
@@ -25,7 +25,6 @@ | |||
25 | */ | 25 | */ |
26 | 26 | ||
27 | 27 | ||
28 | |||
29 | #include "platform.h" | 28 | #include "platform.h" |
30 | #include "gnunet_util_lib.h" | 29 | #include "gnunet_util_lib.h" |
31 | #define TESTSTRING "testString" | 30 | #define TESTSTRING "testString" |
@@ -64,9 +63,14 @@ test_normal_rw (void) | |||
64 | 63 | ||
65 | rh = GNUNET_BIO_read_open_file (filename); | 64 | rh = GNUNET_BIO_read_open_file (filename); |
66 | GNUNET_assert (NULL != rh); | 65 | GNUNET_assert (NULL != rh); |
67 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_spec_commit (rh, rs)); | 66 | GNUNET_assert (GNUNET_OK == |
68 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL)); | 67 | GNUNET_BIO_read_spec_commit (rh, |
69 | GNUNET_assert (0 == strcmp (TESTSTRING, rString)); | 68 | rs)); |
69 | GNUNET_assert (GNUNET_OK == | ||
70 | GNUNET_BIO_read_close (rh, | ||
71 | NULL)); | ||
72 | GNUNET_assert (0 == strcmp (TESTSTRING, | ||
73 | rString)); | ||
70 | GNUNET_assert (wNum == rNum); | 74 | GNUNET_assert (wNum == rNum); |
71 | 75 | ||
72 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); | 76 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); |
@@ -89,7 +93,7 @@ test_normal_rw (void) | |||
89 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL)); | 93 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL)); |
90 | GNUNET_assert (0 == strcmp (TESTSTRING, rString)); | 94 | GNUNET_assert (0 == strcmp (TESTSTRING, rString)); |
91 | GNUNET_assert (wNum == rNum); | 95 | GNUNET_assert (wNum == rNum); |
92 | 96 | GNUNET_free (rString); | |
93 | GNUNET_free (buffer); | 97 | GNUNET_free (buffer); |
94 | 98 | ||
95 | return 0; | 99 | return 0; |