This patch fixes the free operations in ring status get when there is a
failure during memory allocation in the cfg client.

Regards
-steve
Index: lib/cfg.c
===================================================================
--- lib/cfg.c	(revision 2850)
+++ lib/cfg.c	(working copy)
@@ -272,7 +272,7 @@
 	struct cfg_instance *cfg_instance;
 	struct req_lib_cfg_ringstatusget req_lib_cfg_ringstatusget;
 	struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
-	unsigned int i;
+	unsigned int i, j;
 	cs_error_t error;
 	struct iovec iov;
 
@@ -303,7 +303,7 @@
 	*status = malloc (sizeof (char *) * *interface_count);
 	if (*status == NULL) {
 		error = CS_ERR_NO_MEMORY;
-		goto error_free_interface_names;
+		goto error_free_interface_names_array;
 	}
 	memset (*status, 0, sizeof (char *) * *interface_count);
 
@@ -311,25 +311,33 @@
 		(*(interface_names))[i] = strdup (res_lib_cfg_ringstatusget.interface_name[i]);
 		if ((*(interface_names))[i] == NULL) {
 			error = CS_ERR_NO_MEMORY;
-			goto error_free_contents;
+			goto error_free_interface_names;
 		}
+	}
+
+	for (i = 0; i < res_lib_cfg_ringstatusget.interface_count; i++) {
 		(*(status))[i] = strdup (res_lib_cfg_ringstatusget.interface_status[i]);
 		if ((*(status))[i] == NULL) {
 			error = CS_ERR_NO_MEMORY;
-			goto error_free_contents;
+			goto error_free_status;
 		}
 	}
 	goto no_error;
 
-error_free_contents:
-	for (i = 0; i < res_lib_cfg_ringstatusget.interface_count; i++) {
-		free (*interface_names + i);
-		free (*status + i);
+error_free_status:
+	for (j = 0; j < i; j++) {
+		free ((*(status))[j]);
 	}
+	i = *interface_count;
 
+error_free_interface_names:
+	for (j = 0; j < i; j++) {
+		free ((*(interface_names))[j]);
+	}
+	
 	free (*status);
 
-error_free_interface_names:
+error_free_interface_names_array:
 	free (*interface_names);
 
 no_error:
_______________________________________________
Openais mailing list
Openais@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/openais

Reply via email to