From 18f35e4ebd7c241886dd128fd4a0f9f53f0aebc3 Mon Sep 17 00:00:00 2001 From: Murai Takashi Date: Sun, 7 May 2023 15:56:15 +0900 Subject: [PATCH] libroot/os/driver_settings.cpp: fix memory leak MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix leakage of memory allocated to 'text' when new_settings() fails in load_driver_settings() at line 767. Pointed out by Clang Static Analyzer. Change-Id: I5888e2377c4da63040d5a66199f04aebd2034728 Reviewed-on: https://review.haiku-os.org/c/haiku/+/6382 Tested-by: Commit checker robot Reviewed-by: Jérôme Duval --- src/system/libroot/os/driver_settings.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/system/libroot/os/driver_settings.cpp b/src/system/libroot/os/driver_settings.cpp index ae57e606fb..6cff7258c0 100644 --- a/src/system/libroot/os/driver_settings.cpp +++ b/src/system/libroot/os/driver_settings.cpp @@ -764,7 +764,10 @@ load_driver_settings(const char *driverName) return NULL; memcpy(text, settings->buffer, settings->size + 1); - return new_settings(text, driverName); + settings_handle *handle = new_settings(text, driverName); + if (handle == NULL) + free(text); + return handle; } settings = settings->next; }