driver_settings: fix allocating an empty settings

I misread the condition and broke this in 0687a01. Thanks to Axel for
reviewing!
* Refactor the code again to move all the error checking at the top of
the function, to make it easier to read.
This commit is contained in:
Adrien Destugues 2015-01-14 13:39:35 +01:00
parent bcb793d37b
commit 1736cb1d59

View File

@ -828,19 +828,18 @@ load_driver_settings_file(int fd)
void *
parse_driver_settings_string(const char *settingsString)
{
if (settingsString == NULL)
return NULL;
// we simply copy the whole string to use it as our internal buffer
char *text = strdup(settingsString);
if (text != NULL) {
settings_handle *handle = new_settings(text, NULL);
if (handle == NULL)
free(text);
return handle;
char *text = NULL;
if (settingsString != NULL) {
// we simply copy the whole string to use it as our internal buffer
text = strdup(settingsString);
if (text == NULL)
return NULL;
}
return NULL;
settings_handle *handle = new_settings(text, NULL);
if (handle == NULL)
free(text);
return handle;
}