]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: ncbmbuf: improve handling of memory allocation errors in unit tests
authorIlia Shipitsin <chipitsine@gmail.com>
Sun, 31 May 2026 07:14:39 +0000 (09:14 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 31 May 2026 08:29:49 +0000 (10:29 +0200)
Found via cppcheck  --force --enable=all --output-file=haproxy.log :

src/ncbmbuf.c:192:9: warning: If memory allocation fails, then there is a possible null pointer dereference: area [nullPointerOutOfMemory]
src/ncbmbuf.c:373:9: warning: If memory allocation fails, then there is a possible null pointer dereference: data [nullPointerOutOfMemory]
src/ncbmbuf.c:546:9: warning: If memory allocation fails, then there is a possible null pointer dereference: data [nullPointerOutOfMemory]

src/ncbmbuf.c

index 222737ea694715750365866889073cc985871016..e642e3d215e0731ad3cfa1ab5af719439d7b5563 100644 (file)
@@ -370,6 +370,12 @@ void test_ncbmb(void)
        char *data = calloc(16384, 1);
        struct ncbmbuf buf;
 
+       if (!area || !data) {
+               free(area);
+               free(data);
+               return;
+       }
+
        memset(data, 0x11, 16384);
 
        /* 7 bytes data // 1 byte bitmap (0xfe) */
@@ -543,6 +549,12 @@ void test_ngtcp2_crypto(void)
        char *data = calloc(16384, 1);
        struct ncbmbuf buf;
 
+       if (!area || !data) {
+               free(area);
+               free(data);
+               return;
+       }
+
        memset(data, 0x11, 16384);
 
        buf = ncbmb_make(area, 16384, 0);