chiark / gitweb /
tests: fix resource & mem leaks
authorRonny Chevalier <chevalier.ronny@gmail.com>
Thu, 18 Sep 2014 10:09:10 +0000 (12:09 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 18 Sep 2014 10:09:10 +0000 (12:09 +0200)
src/test/test-condition-util.c
src/test/test-fileio.c

index 4ee5600ff6a648131352927c482f51510fd419ea..35ee9167bffb83936acd36c088373c3379b0390c 100644 (file)
@@ -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);
index 92aa794a9513a094b7eee19e2763bf5963acc36e..1b998281912543a927ad00fa42997881d291a523 100644 (file)
@@ -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,8 +317,8 @@ static void test_write_string_stream(void) {
 
 static void test_write_string_file(void) {
         char fn[] = "/tmp/test-write_string_file-XXXXXX";
-        int fd;
-        char buf[64] = {0};
+        char buf[64] = {};
+        _cleanup_close_ int fd;
 
         fd = mkostemp_safe(fn, O_RDWR);
         assert_se(fd >= 0);
@@ -334,8 +334,7 @@ static void test_write_string_file(void) {
 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 in_fd, out_fd;
         char text[] = "boohoo\nfoo\n\tbar\n";
         char buf[64] = {0};