diff options
author | Christian Grothoff <christian@grothoff.org> | 2023-01-17 14:12:49 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2023-01-17 14:12:49 +0100 |
commit | c4156bb96ce7e328a1c2cb4a9f6112818a9a11c1 (patch) | |
tree | 4983f278ed04cbbabe58782e5c424af2355fc9db /src/util/bio.c | |
parent | 31dcac7e27e676a3bd00b8359806cb598d10696a (diff) | |
download | gnunet-c4156bb96ce7e328a1c2cb4a9f6112818a9a11c1.tar.gz gnunet-c4156bb96ce7e328a1c2cb4a9f6112818a9a11c1.zip |
-fix memory leak in test case (#7590)
Diffstat (limited to 'src/util/bio.c')
-rw-r--r-- | src/util/bio.c | 30 |
1 files changed, 17 insertions, 13 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) | |||
510 | struct GNUNET_DISK_FileHandle *fd; | 510 | struct GNUNET_DISK_FileHandle *fd; |
511 | struct GNUNET_BIO_WriteHandle *h; | 511 | struct GNUNET_BIO_WriteHandle *h; |
512 | 512 | ||
513 | fd = | 513 | fd = GNUNET_DISK_file_open (fn, |
514 | GNUNET_DISK_file_open (fn, | 514 | GNUNET_DISK_OPEN_WRITE |
515 | GNUNET_DISK_OPEN_WRITE | 515 | | GNUNET_DISK_OPEN_TRUNCATE |
516 | | GNUNET_DISK_OPEN_TRUNCATE | 516 | | GNUNET_DISK_OPEN_CREATE, |
517 | | GNUNET_DISK_OPEN_CREATE, | 517 | GNUNET_DISK_PERM_USER_READ |
518 | GNUNET_DISK_PERM_USER_READ | 518 | | GNUNET_DISK_PERM_USER_WRITE); |
519 | | GNUNET_DISK_PERM_USER_WRITE); | ||
520 | if (NULL == fd) | 519 | if (NULL == fd) |
521 | return NULL; | 520 | return NULL; |
522 | h = GNUNET_malloc (sizeof(struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE); | 521 | h = GNUNET_malloc (sizeof(struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE); |
@@ -611,14 +610,16 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h) | |||
611 | 610 | ||
612 | if (IO_FILE != h->type) | 611 | if (IO_FILE != h->type) |
613 | return GNUNET_OK; | 612 | return GNUNET_OK; |
614 | 613 | ret = GNUNET_DISK_file_write (h->fd, | |
615 | ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->have); | 614 | h->buffer, |
615 | h->have); | ||
616 | if (ret != (ssize_t) h->have) | 616 | if (ret != (ssize_t) h->have) |
617 | { | 617 | { |
618 | GNUNET_DISK_file_close (h->fd); | 618 | GNUNET_DISK_file_close (h->fd); |
619 | h->fd = NULL; | 619 | h->fd = NULL; |
620 | GNUNET_free (h->emsg); | 620 | GNUNET_free (h->emsg); |
621 | GNUNET_asprintf (&h->emsg, _ ("Unable to flush buffer to file")); | 621 | GNUNET_asprintf (&h->emsg, |
622 | "Unable to flush buffer to file"); | ||
622 | return GNUNET_SYSERR; | 623 | return GNUNET_SYSERR; |
623 | } | 624 | } |
624 | h->have = 0; | 625 | h->have = 0; |
@@ -638,7 +639,7 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h) | |||
638 | * @param size where to store the size of @e contents | 639 | * @param size where to store the size of @e contents |
639 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 640 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
640 | */ | 641 | */ |
641 | int | 642 | enum GNUNET_GenericReturnValue |
642 | GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h, | 643 | GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h, |
643 | char **emsg, | 644 | char **emsg, |
644 | void **contents, | 645 | void **contents, |
@@ -648,7 +649,10 @@ GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h, | |||
648 | return GNUNET_SYSERR; | 649 | return GNUNET_SYSERR; |
649 | if ((NULL == contents) || (NULL == size)) | 650 | if ((NULL == contents) || (NULL == size)) |
650 | return GNUNET_SYSERR; | 651 | return GNUNET_SYSERR; |
651 | int ret = (NULL != h->emsg) ? GNUNET_SYSERR : GNUNET_OK; | 652 | enum GNUNET_GenericReturnValue ret |
653 | = (NULL != h->emsg) | ||
654 | ? GNUNET_SYSERR | ||
655 | : GNUNET_OK; | ||
652 | if (NULL != emsg) | 656 | if (NULL != emsg) |
653 | *emsg = h->emsg; | 657 | *emsg = h->emsg; |
654 | else | 658 | else |
@@ -667,7 +671,7 @@ GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h, | |||
667 | * @param len the number of bytes to write | 671 | * @param len the number of bytes to write |
668 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 672 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
669 | */ | 673 | */ |
670 | static int | 674 | static enum GNUNET_GenericReturnValue |
671 | write_to_file (struct GNUNET_BIO_WriteHandle *h, | 675 | write_to_file (struct GNUNET_BIO_WriteHandle *h, |
672 | const char *what, | 676 | const char *what, |
673 | const char *source, | 677 | const char *source, |