Fixed memory leak.
[gedcom-parse.git] / gom / source_event.c
index 51a4b60cc765ff33782fc41475a4482afdb58efe..319dbb7f8c0b854d2d2fe9d26bbca7ca709e5633 100644 (file)
@@ -38,12 +38,8 @@ Gedcom_ctxt sub_sour_even_start(_ELT_PARAMS_)
   if (! ctxt)
     NO_CONTEXT;
   else {
-    struct source_event *evt
-      = (struct source_event *)malloc(sizeof(struct source_event));
-    if (! evt)
-      MEMORY_ERROR;
-    else {
-      memset (evt, 0, sizeof(struct source_event));
+    struct source_event *evt = SUB_MAKEFUNC(source_event)();
+    if (evt) {
       evt->recorded_events = strdup(GEDCOM_STRING(parsed_value));
 
       if (! evt->recorded_events) {
@@ -65,6 +61,12 @@ Gedcom_ctxt sub_sour_even_start(_ELT_PARAMS_)
   return (Gedcom_ctxt)result;
 }
 
+DEFINE_SUB_MAKEFUNC(source_event)
+DEFINE_SUB_ADDFUNC(source_event)
+DEFINE_SUB_FINDFUNC(source_event)
+DEFINE_SUB_REMOVEFUNC(source_event)
+DEFINE_SUB_MOVEFUNC(source_event)
+     
 DEFINE_DATE_CB(source_event, sub_sour_even_date_start, date_period)
 DEFINE_STRING_CB(source_event, sub_sour_even_plac_start, jurisdiction)
 
@@ -80,6 +82,16 @@ void source_event_subscribe()
                              sub_sour_even_plac_start, def_elt_end);
 }
 
+void UNREFALLFUNC(source_event)(struct source_event* obj)
+{
+  if (obj) {
+    struct source_event* runner;
+    for (runner = obj; runner; runner = runner->next) {
+      UNREFALLFUNC(user_data)(runner->extra);
+    }
+  }
+}
+
 void CLEANFUNC(source_event)(struct source_event* evt)
 {
   if (evt) {