diff options
author | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2018-09-18 22:36:39 +0200 |
---|---|---|
committer | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2018-09-18 22:36:39 +0200 |
commit | 0c43120437a3a4cca4cdbb1b0d23b4088a5cba1a (patch) | |
tree | 361295fe8c260f7acbb176a1b0c5562af1c4510c | |
parent | 9ada9f3f12c5a7e88512cf418f9bdf570b4432ca (diff) | |
download | librb-0c43120437a3a4cca4cdbb1b0d23b4088a5cba1a.tar.gz librb-0c43120437a3a4cca4cdbb1b0d23b4088a5cba1a.tar.bz2 librb-0c43120437a3a4cca4cdbb1b0d23b4088a5cba1a.zip |
fix: file descriptor leak in tests
-rw-r--r-- | tests.c | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -534,6 +534,8 @@ static void multi_thread(void) unsigned char *recv_buf = malloc(t_objsize * buflen); size_t i; int rc; + int fd = -1; + int fd2 = -1; struct rb *rb; struct rb *rb2; @@ -566,9 +568,6 @@ static void multi_thread(void) if (t_multi_test_type == TEST_FD_FILE) { - int fd; - int fd2; - fd2 = open("/tmp/rb-test-file", O_RDWR | O_CREAT | O_TRUNC, 0644); fd = open("/tmp/rb-test-file", O_RDWR | O_CREAT | O_TRUNC, 0644); if (fd < 0 || fd2 < 0) @@ -608,6 +607,8 @@ static void multi_thread(void) c, buflen, t_rblen, t_readlen, t_writelen); }; + close(proddata.fd); + close(consdata.fd); rb_destroy(rb); free(send_buf); free(recv_buf); @@ -1201,6 +1202,7 @@ static void fd_write_single_overlap(void) } rb_destroy(rb); + close(fd); } static void fd_write_single_partial(void) @@ -1618,7 +1620,6 @@ int main(void) unsigned int t_num_consumers_max = 8; char name[128]; - #if ENABLE_THREADS for (t_num_consumers = 1; t_num_consumers <= t_num_consumers_max; t_num_consumers++) |