Only try to delete address if present.
[gedcom-parse.git] / gom / family_link.c
index 39a2140c865b452b3f213231b947ad28a3f6c3fb..4ea3fc1c1bd1911504a671a15dbfacaf8668be0b 100644 (file)
@@ -39,12 +39,8 @@ Gedcom_ctxt sub_fam_link_start(_ELT_PARAMS_)
   if (! ctxt)
     NO_CONTEXT;
   else {
-    struct family_link *link
-      = (struct family_link *)malloc(sizeof(struct family_link));
-    if (! link)
-      MEMORY_ERROR;
-    else {
-      memset (link, 0, sizeof(struct family_link));
+    struct family_link *link = SUB_MAKEFUNC(family_link)();
+    if (link) {
       link->family = GEDCOM_XREF_PTR(parsed_value);
       
       switch (ctxt->ctxt_type) {
@@ -87,6 +83,12 @@ Gedcom_ctxt sub_fam_link_pedi_start(_ELT_PARAMS_)
   return (Gedcom_ctxt)result;
 }
 
+DEFINE_SUB_MAKEFUNC(family_link)
+DEFINE_SUB_ADDFUNC(family_link)
+DEFINE_SUB_FINDFUNC(family_link)
+DEFINE_SUB_REMOVEFUNC(family_link)
+DEFINE_SUB_MOVEFUNC(family_link)
+     
 DEFINE_ADDFUNC2(family_link, note_sub, note)
 DEFINE_ADDFUNC2(family_link, user_data, extra)
 
@@ -100,6 +102,16 @@ void family_link_subscribe()
                              def_elt_end);
 }
 
+void UNREFALLFUNC(pedigree)(struct pedigree* obj)
+{
+  if (obj) {
+    struct pedigree* runner;
+    for (runner = obj; runner; runner = runner->next) {
+      UNREFALLFUNC(user_data)(runner->extra);
+    }
+  }
+}
+
 void CLEANFUNC(pedigree)(struct pedigree* ped)
 {
   if (ped) {
@@ -107,6 +119,25 @@ void CLEANFUNC(pedigree)(struct pedigree* ped)
   }
 }
 
+DEFINE_SUB_MAKEFUNC(pedigree)
+DEFINE_SUB_ADDFUNC(pedigree)
+DEFINE_SUB_FINDFUNC(pedigree)
+DEFINE_SUB_REMOVEFUNC(pedigree)
+DEFINE_SUB_MOVEFUNC(pedigree)
+     
+void UNREFALLFUNC(family_link)(struct family_link* obj)
+{
+  if (obj) {
+    struct family_link* runner;
+    for (runner = obj; runner; runner = runner->next) {
+      unref_xref_value(runner->family);
+      UNREFALLFUNC(pedigree)(runner->pedigree);
+      UNREFALLFUNC(note_sub)(runner->note);
+      UNREFALLFUNC(user_data)(runner->extra);
+    }
+  }
+}
+
 void CLEANFUNC(family_link)(struct family_link *link)
 {
   if (link) {