[systemd-devel] [PATCH] tests: fix resource & mem leaks

Ronny Chevalier chevalier.ronny at gmail.com
Wed Sep 17 11:10:43 PDT 2014


---
 src/test/test-condition-util.c | 2 +-
 src/test/test-fileio.c         | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/test/test-condition-util.c b/src/test/test-condition-util.c
index 4ee5600..35ee916 100644
--- a/src/test/test-condition-util.c
+++ b/src/test/test-condition-util.c
@@ -45,7 +45,7 @@ static void test_condition_test_host(void) {
         sd_id128_t id;
         int r;
         char sid[SD_ID128_STRING_MAX];
-        char *hostname;
+        _cleanup_free_ char *hostname = NULL;
 
         r = sd_id128_get_machine(&id);
         assert_se(r >= 0);
diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c
index 344cc1f..078e802 100644
--- a/src/test/test-fileio.c
+++ b/src/test/test-fileio.c
@@ -303,7 +303,7 @@ static void test_write_string_stream(void) {
         assert_se(f);
         assert_se(write_string_stream(f, "boohoo") < 0);
 
-        f = fdopen(fd, "r+");
+        f = freopen(fn, "r+", f);
         assert_se(f);
 
         assert_se(write_string_stream(f, "boohoo") == 0);
@@ -317,7 +317,7 @@ static void test_write_string_stream(void) {
 
 static void test_write_string_file(void) {
         char fn[] = "/tmp/test-write_string_file-XXXXXX";
-        int fd;
+        _cleanup_close_ int fd;
         char buf[64] = {0};
 
         fd = mkostemp_safe(fn, O_RDWR);
@@ -333,7 +333,7 @@ static void test_write_string_file(void) {
 
 static void test_write_string_file_no_create(void) {
         char fn[] = "/tmp/test-write_string_file_no_create-XXXXXX";
-        int fd;
+        _cleanup_close_ int fd;
         char buf[64] = {0};
 
         fd = mkostemp_safe(fn, O_RDWR);
@@ -352,7 +352,7 @@ static void test_sendfile_full(void) {
         char in_fn[] = "/tmp/test-sendfile_full-XXXXXX";
         char out_fn[] = "/tmp/test-sendfile_full-XXXXXX";
         _cleanup_close_ int in_fd = -1;
-        int out_fd;
+        _cleanup_close_ int out_fd = -1;
         char text[] = "boohoo\nfoo\n\tbar\n";
         char buf[64] = {0};
 
-- 
2.1.0



More information about the systemd-devel mailing list