Преглед изворни кода

defect 1030
This fixes the event handle leak on failure, the malloc check for hl,
removes the redundant memset when creating a handle, and makes sure
that the put of the channel handle is a valid handle.



git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@886 fd59a12c-fef9-0310-b244-a6a79926bd2f

Mark Haverkamp пре 20 година
родитељ
комит
518a62fc05
1 измењених фајлова са 7 додато и 3 уклоњено
  1. 7 3
      lib/evt.c

+ 7 - 3
lib/evt.c

@@ -1354,11 +1354,10 @@ saEvtEventAllocate(
 	error = saHandleInstanceGet(&event_handle_db, *eventHandle,
 	error = saHandleInstanceGet(&event_handle_db, *eventHandle,
 					(void*)&edi);
 					(void*)&edi);
 	if (error != SA_AIS_OK) {
 	if (error != SA_AIS_OK) {
+		saHandleDestroy(&event_handle_db, *eventHandle);
 		goto alloc_put2;
 		goto alloc_put2;
 	}
 	}
 
 
-	memset(edi, 0, sizeof(*edi));
-
 	pthread_mutex_init(&edi->edi_mutex, NULL);
 	pthread_mutex_init(&edi->edi_mutex, NULL);
 	edi->edi_ro = 0;
 	edi->edi_ro = 0;
 	edi->edi_freeing = 0;
 	edi->edi_freeing = 0;
@@ -1369,6 +1368,11 @@ saEvtEventAllocate(
 	edi->edi_pub_time = SA_TIME_UNKNOWN;
 	edi->edi_pub_time = SA_TIME_UNKNOWN;
 	edi->edi_retention_time = 0;
 	edi->edi_retention_time = 0;
 	hl = malloc(sizeof(*hl));
 	hl = malloc(sizeof(*hl));
+	if (!hl) {
+		saHandleDestroy(&event_handle_db, *eventHandle);
+		error = SA_AIS_ERR_NO_MEMORY;
+		goto alloc_put2;
+	}
 	edi->edi_hl = hl;
 	edi->edi_hl = hl;
 	hl->hl_handle = *eventHandle;
 	hl->hl_handle = *eventHandle;
 	list_init(&hl->hl_entry);
 	list_init(&hl->hl_entry);
@@ -1380,7 +1384,7 @@ saEvtEventAllocate(
 alloc_put2:
 alloc_put2:
 	saHandleInstancePut (&evt_instance_handle_db, eci->eci_instance_handle);
 	saHandleInstancePut (&evt_instance_handle_db, eci->eci_instance_handle);
 alloc_put1:
 alloc_put1:
-	saHandleInstancePut (&channel_handle_db, edi->edi_channel_handle);
+	saHandleInstancePut (&channel_handle_db, channelHandle);
 alloc_done:
 alloc_done:
 	return error;
 	return error;
 }
 }