chiark / gitweb /
test: fix mem-leak in fdopen() test
authorDavid Herrmann <dh.herrmann@gmail.com>
Thu, 11 Sep 2014 15:37:30 +0000 (17:37 +0200)
committerDavid Herrmann <dh.herrmann@gmail.com>
Thu, 11 Sep 2014 15:39:17 +0000 (17:39 +0200)
We must free FILE* after function return to not leak resources. Note that
this also closes our fd as fdopen() takes ownership of it.
Reported by Philippe De Swert (via coverity).

src/test/test-util.c

index 72a8a6b1301ae41c871554703a121824553c4967..80425ca61a3aa176ae7e7564147e756e0f02e732 100644 (file)
@@ -918,11 +918,11 @@ static void test_readlink_and_make_absolute(void) {
 }
 
 static void test_read_one_char(void) {
+        _cleanup_fclose_ FILE *file = NULL;
         char r;
         bool need_nl;
         char name[] = "/tmp/test-read_one_char.XXXXXX";
-        _cleanup_close_ int fd = -1;
-        FILE *file;
+        int fd;
 
         fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
         assert_se(fd >= 0);