Browse Source

Fix queue items memory leak.

(Logical change 1.49)


git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@153 fd59a12c-fef9-0310-b244-a6a79926bd2f
Mark Haverkamp 21 years ago
parent
commit
aa5a8389ef
1 changed files with 18 additions and 0 deletions
  1. 18 0
      lib/evt.c

+ 18 - 0
lib/evt.c

@@ -180,11 +180,28 @@ struct message_overlay {
 static void evtHandleInstanceDestructor(void *instance)
 {
 	struct event_instance *evti = instance;
+	void **msg;
+	int empty;
+
+	/*
+	 * Empty out the queue if there are any pending messages
+	 */
+	while ((saQueueIsEmpty(&evti->ei_inq, &empty) == SA_OK) && !empty) {
+		saQueueItemGet(&evti->ei_inq, &msg);
+		saQueueItemRemove(&evti->ei_inq);
+		free(*msg);
+	}
 
+	/*
+	 * clean up the queue itself
+	 */
 	if (evti->ei_inq.items) {
 			free(evti->ei_inq.items);
 	}
 
+	/*
+	 * Disconnect from the server
+	 */
 	if (evti->ei_fd != -1) {
 		shutdown(evti->ei_fd, 0);
 		close(evti->ei_fd);
@@ -409,6 +426,7 @@ saEvtDispatch(
 			msg = *queue_msg;
 			memcpy(&dispatch_data, msg, msg->size);
 			saQueueItemRemove(&evti->ei_inq);
+			free(msg);
 		} else {
 			/*
 			 * Queue empty, read response from socket