Index: src/wildmidi_lib.c
===================================================================
--- src/wildmidi_lib.c	(revision 39)
+++ src/wildmidi_lib.c	(working copy)
@@ -3488,7 +3488,6 @@
 		first_handle->next = NULL;
 	} else {
 		tmp_handle = first_handle;
-			free(tmp_trackdata);
 		if (tmp_handle->next != NULL) {
 			while (tmp_handle->next != NULL)
 				tmp_handle = tmp_handle->next;
@@ -3496,6 +3495,7 @@
 		tmp_handle->next = malloc(sizeof(struct _hndl));
 		if (tmp_handle->next == NULL) {
 			WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM," to parse midi data", errno);
+			free(tmp_trackdata);
 			free(mdi->data);
 			free(mdi);
 			return NULL;
