Explorar el Código

coroparse: Free kv_item key and value on failure

If strdup of kv_item key or value failed only kv_item itself was freed.
Free also key and value (kv_item is zeroed so free of NULL variable is
safe).

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Christine Caulfield <ccaulfie@redhat.com>
Jan Friesse hace 1 año
padre
commit
02d64060c1
Se han modificado 1 ficheros con 6 adiciones y 0 borrados
  1. 6 0
      exec/coroparse.c

+ 6 - 0
exec/coroparse.c

@@ -951,6 +951,8 @@ static int main_config_parser_cb(const char *path,
 				kv_item->key = strdup(key);
 				kv_item->value = strdup(value);
 				if (kv_item->key == NULL || kv_item->value == NULL) {
+					free(kv_item->key);
+					free(kv_item->value);
 					free(kv_item);
 					*error_string = "Can't alloc memory";
 
@@ -988,6 +990,8 @@ static int main_config_parser_cb(const char *path,
 				kv_item->key = strdup(key);
 				kv_item->value = strdup(value);
 				if (kv_item->key == NULL || kv_item->value == NULL) {
+					free(kv_item->key);
+					free(kv_item->value);
 					free(kv_item);
 					*error_string = "Can't alloc memory";
 
@@ -1046,6 +1050,8 @@ static int main_config_parser_cb(const char *path,
 			kv_item->key = strdup(key);
 			kv_item->value = strdup(value);
 			if (kv_item->key == NULL || kv_item->value == NULL) {
+				free(kv_item->key);
+				free(kv_item->value);
 				free(kv_item);
 				*error_string = "Can't alloc memory";