qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] build: Fix --enable-sanitizers build errors
@ 2023-03-01 16:05 Daniel Xu
  2023-03-01 16:05 ` [PATCH 1/2] crypto/luks: Initialize stack variable to silence warning Daniel Xu
  2023-03-01 16:05 ` [PATCH 2/2] qemu-keymap: Fix memory leaks Daniel Xu
  0 siblings, 2 replies; 3+ messages in thread
From: Daniel Xu @ 2023-03-01 16:05 UTC (permalink / raw)
  To: qemu-devel, marcandre.lureau, berrange

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/cover.1677617035.git.dxu@dxuuu.xyz/

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(-)

-- 
2.39.1



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] crypto/luks: Initialize stack variable to silence warning
  2023-03-01 16:05 [PATCH 0/2] build: Fix --enable-sanitizers build errors Daniel Xu
@ 2023-03-01 16:05 ` Daniel Xu
  2023-03-01 16:05 ` [PATCH 2/2] qemu-keymap: Fix memory leaks Daniel Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Xu @ 2023-03-01 16:05 UTC (permalink / raw)
  To: Daniel P. Berrangé marcandre . lureau @ gmail . com; +Cc: qemu-devel

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.

Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
---
 crypto/block-luks.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/crypto/block-luks.c b/crypto/block-luks.c
index 5688783ab1..bfdef25c80 100644
--- a/crypto/block-luks.c
+++ b/crypto/block-luks.c
@@ -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;
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] qemu-keymap: Fix memory leaks
  2023-03-01 16:05 [PATCH 0/2] build: Fix --enable-sanitizers build errors Daniel Xu
  2023-03-01 16:05 ` [PATCH 1/2] crypto/luks: Initialize stack variable to silence warning Daniel Xu
@ 2023-03-01 16:05 ` Daniel Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Xu @ 2023-03-01 16:05 UTC (permalink / raw)
  To: marcandre.lureau, berrange; +Cc: qemu-devel, Marc-André Lureau

When 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.

Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 qemu-keymap.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/qemu-keymap.c b/qemu-keymap.c
index 229866e004..ed8cee3467 100644
--- a/qemu-keymap.c
+++ b/qemu-keymap.c
@@ -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,
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-03-01 16:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-01 16:05 [PATCH 0/2] build: Fix --enable-sanitizers build errors Daniel Xu
2023-03-01 16:05 ` [PATCH 1/2] crypto/luks: Initialize stack variable to silence warning Daniel Xu
2023-03-01 16:05 ` [PATCH 2/2] qemu-keymap: Fix memory leaks Daniel Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).