]> git.meshlink.io Git - utcp/commitdiff
Always check the return value of malloc().
authorGuus Sliepen <guus@meshlink.io>
Thu, 29 Oct 2015 15:26:54 +0000 (16:26 +0100)
committerGuus Sliepen <guus@sliepen.org>
Sun, 2 Jul 2017 10:05:40 +0000 (12:05 +0200)
test.c
utcp.c

diff --git a/test.c b/test.c
index 47732e47e7c31cfce6b1674eb5ec2ef08a8388b2..3491e296c9a558a6b587d63cec23702f65ec4b21 100644 (file)
--- a/test.c
+++ b/test.c
@@ -73,6 +73,10 @@ ssize_t do_send(struct utcp *utcp, const void *data, size_t len) {
                        return len;
                if(!reorder_data && drand48() < reorder) {
                        reorder_data = malloc(len);
+                       if(!reorder_data) {
+                               debug("Out of memory\n");
+                               return len;
+                       }
                        reorder_len = len;
                        memcpy(reorder_data, data, len);
                        reorder_countdown = 1 + drand48() * reorder_dist;
diff --git a/utcp.c b/utcp.c
index 607af2d149ee9242646d3f1a97638ecb64e01078..95a82c428710ca91f5f2752045eea036bee40c79 100644 (file)
--- a/utcp.c
+++ b/utcp.c
@@ -88,6 +88,10 @@ static void print_packet(struct utcp *utcp, const char *dir, const void *pkt, si
        if(len > sizeof hdr) {
                uint32_t datalen = len - sizeof hdr;
                uint8_t *str = malloc((datalen << 1) + 7);
+               if(!str) {
+                       debug("out of memory");
+                       return;
+               }
                memcpy(str, " data=", 6);
                uint8_t *strptr = str + 6;
                const uint8_t *data = pkt;