Ver Fonte

Merge trunk revision 2852:
r2852 | sdake | 2010-05-18 10:20:05 -0700 (Tue, 18 May 2010) | 3 lines

Fix free of ring status information when memory allocation fails during
allocation of the ring status information.



git-svn-id: http://svn.fedorahosted.org/svn/corosync/branches/flatiron@2894 fd59a12c-fef9-0310-b244-a6a79926bd2f

Steven Dake há 15 anos atrás
pai
commit
4aea041600
1 ficheiros alterados com 17 adições e 9 exclusões
  1. 17 9
      lib/cfg.c

+ 17 - 9
lib/cfg.c

@@ -272,7 +272,7 @@ corosync_cfg_ring_status_get (
 	struct cfg_instance *cfg_instance;
 	struct cfg_instance *cfg_instance;
 	struct req_lib_cfg_ringstatusget req_lib_cfg_ringstatusget;
 	struct req_lib_cfg_ringstatusget req_lib_cfg_ringstatusget;
 	struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
 	struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
-	unsigned int i;
+	unsigned int i, j;
 	cs_error_t error;
 	cs_error_t error;
 	struct iovec iov;
 	struct iovec iov;
 
 
@@ -303,7 +303,7 @@ corosync_cfg_ring_status_get (
 	*status = malloc (sizeof (char *) * *interface_count);
 	*status = malloc (sizeof (char *) * *interface_count);
 	if (*status == NULL) {
 	if (*status == NULL) {
 		error = CS_ERR_NO_MEMORY;
 		error = CS_ERR_NO_MEMORY;
-		goto error_free_interface_names;
+		goto error_free_interface_names_array;
 	}
 	}
 	memset (*status, 0, sizeof (char *) * *interface_count);
 	memset (*status, 0, sizeof (char *) * *interface_count);
 
 
@@ -311,25 +311,33 @@ corosync_cfg_ring_status_get (
 		(*(interface_names))[i] = strdup (res_lib_cfg_ringstatusget.interface_name[i]);
 		(*(interface_names))[i] = strdup (res_lib_cfg_ringstatusget.interface_name[i]);
 		if ((*(interface_names))[i] == NULL) {
 		if ((*(interface_names))[i] == NULL) {
 			error = CS_ERR_NO_MEMORY;
 			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]);
 		(*(status))[i] = strdup (res_lib_cfg_ringstatusget.interface_status[i]);
 		if ((*(status))[i] == NULL) {
 		if ((*(status))[i] == NULL) {
 			error = CS_ERR_NO_MEMORY;
 			error = CS_ERR_NO_MEMORY;
-			goto error_free_contents;
+			goto error_free_status;
 		}
 		}
 	}
 	}
 	goto no_error;
 	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);
 	free (*status);
 
 
-error_free_interface_names:
+error_free_interface_names_array:
 	free (*interface_names);
 	free (*interface_names);
 
 
 no_error:
 no_error: