build: Fix --enable-sanitizers build errors
cover build: Fix --enable-sanitizers build errors
I hit two small build errors when building with --enable-sanitizers. These two fixes are split out from a previous series [0].
[0]: https://lore.kernel.org/qemu-devel/[email protected]/
Daniel Xu (2):
crypto/luks: Initialize stack variable to silence warning
qemu-keymap: Fix memory leaks
crypto/block-luks.c | 2 +- qemu-keymap.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-)
Signature · 1 line
2.39.1
PATCH 1/2 crypto/luks: Initialize stack variable to silence warning
With ../configure --enable-sanitizers, I was getting the following build error:
In file included from /usr/include/string.h:535,
from /home/dxu/dev/qemu/include/qemu/osdep.h:99, from ../crypto/block-luks.c:21:
In function ‘memset’,
inlined from ‘qcrypto_block_luks_store_key’ at ../crypto/block-luks.c:843:9:
/usr/include/bits/string_fortified.h:59:10: error: ‘splitkeylen’ may be used uninitialized [-Werror=maybe-uninitialized]
59 | return __builtin___memset_chk (__dest, __ch, __len,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
60 | __glibc_objsize0 (__dest));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
../crypto/block-luks.c: In function ‘qcrypto_block_luks_store_key’:
../crypto/block-luks.c:699:12: note: ‘splitkeylen’ was declared here
699 | size_t splitkeylen;
| ^~~~~~~~~~~
cc1: all warnings being treated as errors
The function is actually correct -- in the cleanup branch splitkeylen usage is guarded by checking splitkey nullness. But the compiler is not smart enough to realize that.
Fix warning by initializing the variable.
--- crypto/block-luks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/block-luks.c +1 -1
@@ -696,7 +696,7 @@ qcrypto_block_luks_store_key(QCryptoBlock *block,QCryptoBlockLUKS *luks = block->opaque;QCryptoBlockLUKSKeySlot *slot; g_autofree uint8_t *splitkey = NULL; -size_t splitkeylen; +size_t splitkeylen =0 ; g_autofree uint8_t *slotkey = NULL;g_autoptr (QCryptoCipher) cipher =NULL ;g_autoptr (QCryptoIVGen) ivgen =NULL ;
Signature · 1 line
2.39.1
PATCH 2/2 qemu-keymap: Fix memory leaks
In reply to Daniel XuWhen building with --enable-sanitizers, I was getting quite a few memory leak crashes from ASAN:
[21/574] Generating pc-bios/keymaps/fr-ch with a custom command
FAILED: pc-bios/keymaps/fr-ch
/home/dxu/dev/qemu/build/qemu-keymap -f pc-bios/keymaps/fr-ch -l ch -v fr
=================================================================
==3232549==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 1424 byte(s) in 1 object(s) allocated from:
#0 0x7f32636bf411 in __interceptor_calloc /usr/src/debug/gcc/gcc/...
#1 0x7f32635db73e (/usr/lib/libxkbcommon.so.0+0x2273e)Fix leaks by correctly decrementing refcounts on xkb structs.
--- qemu-keymap.c | 5 +++++ 1 file changed, 5 insertions(+)
qemu-keymap.c +5 -0
@@ -203,6 +203,7 @@ int main(int argc, char *argv[]) map =xkb_keymap_new_from_names (ctx, &names,XKB_KEYMAP_COMPILE_NO_FLAGS );if (!map) {/* libxkbcommon prints error */ +xkb_context_unref (ctx);exit (1 ); }
@@ -227,7 +228,11 @@ int main(int argc, char *argv[]) state =xkb_state_new (map);xkb_keymap_key_for_each (map, walk_map, state);xkb_state_unref (state); +xkb_keymap_unref (map); +xkb_context_unref (ctx); state =NULL ; + map =NULL ; + ctx =NULL ;/* add quirks */ fprintf(outfile,
Signature · 1 line
2.39.1