From: Evgeny Vereshchagin Date: Thu, 16 Aug 2018 06:48:06 +0000 (+0000) Subject: resolvectl: free the block of memory 'hashed' points to before reusing it X-Git-Tag: v240~836^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=670e95aecda39c49a9ae9c2544203b628ed34d8b;p=platform%2Fupstream%2Fsystemd.git resolvectl: free the block of memory 'hashed' points to before reusing it 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). ``` --- diff --git a/src/resolve/resolvectl.c b/src/resolve/resolvectl.c index f8372d5..1ac4683 100644 --- a/src/resolve/resolvectl.c +++ b/src/resolve/resolvectl.c @@ -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");