From 63719a43229685a262e4ed744c37699c12f36865 Mon Sep 17 00:00:00 2001 From: hirorogo Date: Wed, 1 Apr 2026 02:15:49 +0900 Subject: [PATCH] Fix NULL pointer dereference in freenect_init_registration_table() Add NULL checks after malloc() calls for regtable_dx and regtable_dy. Previously, if either allocation failed, the code would dereference NULL pointers in the subsequent memset() and array access operations. On allocation failure, free any partially allocated buffer and return early to avoid undefined behavior. Co-Authored-By: Claude Opus 4.6 --- src/registration.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/registration.c b/src/registration.c index cbbf557a..459547fa 100644 --- a/src/registration.c +++ b/src/registration.c @@ -288,6 +288,11 @@ static void freenect_init_registration_table(int32_t (*registration_table)[2], f double* regtable_dx = (double*)malloc(DEPTH_X_RES*DEPTH_Y_RES*sizeof(double)); double* regtable_dy = (double*)malloc(DEPTH_X_RES*DEPTH_Y_RES*sizeof(double)); + if (!regtable_dx || !regtable_dy) { + free(regtable_dx); + free(regtable_dy); + return; + } memset(regtable_dx, 0, DEPTH_X_RES*DEPTH_Y_RES * sizeof(double)); memset(regtable_dy, 0, DEPTH_X_RES*DEPTH_Y_RES * sizeof(double)); int32_t x,y,index = 0;