]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolvectl: free the block of memory 'hashed' points to before reusing it 9879/head
authorEvgeny Vereshchagin <evvers@ya.ru>
Thu, 16 Aug 2018 06:48:06 +0000 (06:48 +0000)
committerEvgeny Vereshchagin <evvers@ya.ru>
Thu, 16 Aug 2018 06:48:06 +0000 (06:48 +0000)
This fixes a memory leak:
```
d5070e2f67ededca022f81f2941900606b16f3196b2268e856295f59._openpgpkey.gmail.com: resolve call failed: 'd5070e2f67ededca022f81f2941900606b16f3196b2268e856295f59._openpgpkey.gmail.com' not found

=================================================================
==224==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 65 byte(s) in 1 object(s) allocated from:
    #0 0x7f71b0878850 in malloc (/usr/lib64/libasan.so.4+0xde850)
    #1 0x7f71afaf69b0 in malloc_multiply ../src/basic/alloc-util.h:63
    #2 0x7f71afaf6c95 in hexmem ../src/basic/hexdecoct.c:62
    #3 0x7f71afbb574b in string_hashsum ../src/basic/gcrypt-util.c:45
    #4 0x56201333e0b9 in string_hashsum_sha256 ../src/basic/gcrypt-util.h:30
    #5 0x562013347b63 in resolve_openpgp ../src/resolve/resolvectl.c:908
    #6 0x562013348b9f in verb_openpgp ../src/resolve/resolvectl.c:944
    #7 0x7f71afbae0b0 in dispatch_verb ../src/basic/verbs.c:119
    #8 0x56201335790b in native_main ../src/resolve/resolvectl.c:2947
    #9 0x56201335880d in main ../src/resolve/resolvectl.c:3087
    #10 0x7f71ad8fcf29 in __libc_start_main (/lib64/libc.so.6+0x20f29)

SUMMARY: AddressSanitizer: 65 byte(s) leaked in 1 allocation(s).
```

src/resolve/resolvectl.c

index f8372d5e83a096d655394b18f02b852eddd31c3e..1ac4683c5fcba6a4f77dd6d34453c4c25ffff84c 100644 (file)
@@ -919,7 +919,7 @@ static int resolve_openpgp(sd_bus *bus, const char *address) {
                            arg_type ?: DNS_TYPE_OPENPGPKEY, false);
 
         if (IN_SET(r, -ENXIO, -ESRCH)) { /* NXDOMAIN or NODATA? */
-              hashed = NULL;
+              hashed = mfree(hashed);
               r = string_hashsum_sha224(address, domain - 1 - address, &hashed);
               if (r < 0)
                     return log_error_errno(r, "Hashing failed: %m");