]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared: fix a memory leak 7559/head
authorEvgeny Vereshchagin <evvers@ya.ru>
Wed, 6 Dec 2017 19:12:05 +0000 (19:12 +0000)
committerEvgeny Vereshchagin <evvers@ya.ru>
Wed, 6 Dec 2017 19:31:28 +0000 (19:31 +0000)
```
$ ./src/test/test-systemd-tmpfiles.py valgrind --leak-check=full --error-exitcode=1 ./build/systemd-tmpfiles
...
Running valgrind --leak-check=full --error-exitcode=1 ./build/systemd-tmpfiles on 'w /unresolved/argument - - - - "%Y"'
...
[<stdin>:1] Failed to substitute specifiers in argument: Invalid slot
...
==22602== 5 bytes in 1 blocks are definitely lost in loss record 1 of 2
==22602==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==22602==    by 0x4ECA7D4: malloc_multiply (alloc-util.h:74)
==22602==    by 0x4ECA909: specifier_printf (specifier.c:59)
==22602==    by 0x113490: specifier_expansion_from_arg (tmpfiles.c:1923)
==22602==    by 0x1144E7: parse_line (tmpfiles.c:2159)
==22602==    by 0x11551C: read_config_file (tmpfiles.c:2425)
==22602==    by 0x115AB0: main (tmpfiles.c:2529)
```

src/shared/specifier.c

index 6839d1892dac759d264c85b0f1506274854c34ab..69fefc8d008b4359cff0d96cc7be09c1a706e6df 100644 (file)
@@ -101,10 +101,11 @@ int specifier_printf(const char *text, const Specifier table[], void *userdata,
 
                                         ret = n;
                                         t = n + j + k;
-                                } else if (strchr(POSSIBLE_SPECIFIERS, *f))
+                                } else if (strchr(POSSIBLE_SPECIFIERS, *f)) {
                                         /* Oops, an unknown specifier. */
+                                        free(ret);
                                         return -EBADSLT;
-                                else {
+                                else {
                                         *(t++) = '%';
                                         *(t++) = *f;
                                 }