libroot/os/driver_settings.cpp: fix memory leak

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 <no-reply+buildbot@haiku-os.org>
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
This commit is contained in:
Murai Takashi 2023-05-07 15:56:15 +09:00 committed by Jérôme Duval
parent cfbfb8473c
commit 18f35e4ebd

View File

@ -764,7 +764,10 @@ load_driver_settings(const char *driverName)
return NULL; return NULL;
memcpy(text, settings->buffer, settings->size + 1); 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; settings = settings->next;
} }