diff options
author | Frantisek Sumsal <frantisek@sumsal.cz> | 2023-03-27 16:51:00 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-03-28 13:41:55 +0900 |
commit | 30dbadf65eaa64daa494118eb0cec7750f376c25 (patch) | |
tree | aedf0d079bb3311b8b51edf8e57b97e253068cd7 /src/cryptenroll | |
parent | 485d32d788116961e3184e61779a9e401bf3a353 (diff) | |
download | systemd-30dbadf65eaa64daa494118eb0cec7750f376c25.tar.gz |
cryptenroll: fix a memory leak
$ dd if=/dev/zero of=luks.img bs=1M count=64
$ echo 1231dfsd234d | cryptsetup luksFormat luks.img
$ build-san/systemd-cryptenroll luks.img
SLOT TYPE
0 password
=================================================================
==640364==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 64 byte(s) in 1 object(s) allocated from:
#0 0x7f43ffeb95b5 in __interceptor_realloc.part.0 (/lib64/libasan.so.8+0xb95b5)
#1 0x7f43ff0a4f2f in greedy_realloc ../src/basic/alloc-util.c:70
#2 0x404d9f in list_enrolled ../src/cryptenroll/cryptenroll-list.c:30
#3 0x40f149 in run ../src/cryptenroll/cryptenroll.c:673
#4 0x40f149 in main ../src/cryptenroll/cryptenroll.c:692
#5 0x7f43fd64a50f in __libc_start_call_main (/lib64/libc.so.6+0x2750f)
SUMMARY: AddressSanitizer: 64 byte(s) leaked in 1 allocation(s).
Aborted (core dumped)
Reported in https://github.com/systemd/systemd/pull/27007.
Diffstat (limited to 'src/cryptenroll')
-rw-r--r-- | src/cryptenroll/cryptenroll-list.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/cryptenroll/cryptenroll-list.c b/src/cryptenroll/cryptenroll-list.c index 62688da3d3..d21df7123b 100644 --- a/src/cryptenroll/cryptenroll-list.c +++ b/src/cryptenroll/cryptenroll-list.c @@ -5,12 +5,13 @@ #include "format-table.h" #include "parse-util.h" -int list_enrolled(struct crypt_device *cd) { +struct keyslot_metadata { + int slot; + const char *type; +}; - struct keyslot_metadata { - int slot; - const char *type; - } *keyslot_metadata = NULL; +int list_enrolled(struct crypt_device *cd) { + _cleanup_free_ struct keyslot_metadata *keyslot_metadata = NULL; _cleanup_(table_unrefp) Table *t = NULL; size_t n_keyslot_metadata = 0; int slot_max, r; |