From edb4dfc4869bdd1d1048c88842f9e1ae8bcd3c85 Mon Sep 17 00:00:00 2001
From: iphydf <iphydf@users.noreply.github.com>
Date: Sun, 19 Jan 2025 15:01:15 +0000
Subject: [PATCH] fix: Don't crash on malloc failures in bin_unpack.

---
 toxcore/bin_unpack.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/toxcore/bin_unpack.c b/toxcore/bin_unpack.c
index db255a438b..e3110946bf 100644
--- a/toxcore/bin_unpack.c
+++ b/toxcore/bin_unpack.c
@@ -125,6 +125,10 @@ bool bin_unpack_bin(Bin_Unpack *bu, uint8_t **data_ptr, uint32_t *data_length_pt
     }
     uint8_t *const data = (uint8_t *)mem_balloc(bu->mem, bin_size);
 
+    if (data == nullptr) {
+        return false;
+    }
+
     if (!bin_unpack_bin_b(bu, data, bin_size)) {
         mem_delete(bu->mem, data);
         return false;