From 327069289a45ed1e91d8bfc07d7d89cfbad057d6 Mon Sep 17 00:00:00 2001 From: Peter Verthez Date: Sun, 12 Jan 2003 16:18:03 +0000 Subject: [PATCH] Unlink xrefs properly when struct is deleted. --- gom/address.c | 7 +++++++ gom/address.h | 1 + gom/association.c | 13 +++++++++++++ gom/association.h | 1 + gom/change_date.c | 8 ++++++++ gom/change_date.h | 2 ++ gom/event.c | 16 ++++++++++++++++ gom/event.h | 1 + gom/family.c | 18 ++++++++++++++++++ gom/family_link.c | 23 +++++++++++++++++++++++ gom/family_link.h | 1 + gom/func_template.h | 13 ++++++++++--- gom/gom_internal.h | 2 ++ gom/gom_modify.c | 17 +++++++++++++++++ gom/individual.c | 23 +++++++++++++++++++++++ gom/lds_event.c | 13 +++++++++++++ gom/lds_event.h | 1 + gom/multimedia.c | 11 +++++++++++ gom/multimedia_link.c | 12 ++++++++++++ gom/multimedia_link.h | 1 + gom/note.c | 10 ++++++++++ gom/note_sub.c | 12 ++++++++++++ gom/note_sub.h | 1 + gom/personal_name.c | 12 ++++++++++++ gom/personal_name.h | 2 ++ gom/place.c | 9 +++++++++ gom/place.h | 1 + gom/repository.c | 11 +++++++++++ gom/source.c | 16 ++++++++++++++++ gom/source_citation.c | 23 +++++++++++++++++++++++ gom/source_citation.h | 1 + gom/source_description.c | 10 ++++++++++ gom/source_description.h | 1 + gom/source_event.c | 10 ++++++++++ gom/source_event.h | 1 + gom/submission.c | 18 +++++++++++++----- gom/submitter.c | 10 ++++++++++ gom/user_rec.c | 17 +++++++++++++++++ gom/user_rec.h | 1 + gom/user_ref.c | 9 +++++++++ gom/user_ref.h | 1 + 41 files changed, 352 insertions(+), 8 deletions(-) diff --git a/gom/address.c b/gom/address.c index fa8a3ee..b0d49a0 100644 --- a/gom/address.c +++ b/gom/address.c @@ -147,6 +147,13 @@ void address_subscribe() gedcom_subscribe_to_element(ELT_SUB_PHON, sub_phon_start, def_elt_end); } +void UNREFALLFUNC(address)(struct address *address) +{ + if (address) { + UNREFALLFUNC(user_data)(address->extra); + } +} + void CLEANFUNC(address)(struct address *address) { if (address) { diff --git a/gom/address.h b/gom/address.h index 8c35b2e..b738247 100644 --- a/gom/address.h +++ b/gom/address.h @@ -31,6 +31,7 @@ int write_address(Gedcom_write_hndl hndl, int parent, struct address *address); DECLARE_SUB_MAKEFUNC(address); +DECLARE_UNREFALLFUNC(address); DECLARE_CLEANFUNC(address); DECLARE_ADDFUNC2(address, user_data); diff --git a/gom/association.c b/gom/association.c index 2d9cc2d..9398bbc 100644 --- a/gom/association.c +++ b/gom/association.c @@ -97,6 +97,19 @@ void association_subscribe() def_elt_end); } +void UNREFALLFUNC(association)(struct association *obj) +{ + if (obj) { + struct association* runner; + for (runner = obj; runner; runner = runner->next) { + unref_xref_value(runner->to); + UNREFALLFUNC(source_citation)(runner->citation); + UNREFALLFUNC(note_sub)(runner->note); + UNREFALLFUNC(user_data)(runner->extra); + } + } +} + void CLEANFUNC(association)(struct association* assoc) { if (assoc) { diff --git a/gom/association.h b/gom/association.h index 8c49023..69d56fa 100644 --- a/gom/association.h +++ b/gom/association.h @@ -33,6 +33,7 @@ int write_associations(Gedcom_write_hndl hndl, int parent, DECLARE_SUB_MAKEFUNC(association); +DECLARE_UNREFALLFUNC(association); DECLARE_CLEANFUNC(association); DECLARE_ADDFUNC2(association, note_sub); DECLARE_ADDFUNC2(association, source_citation); diff --git a/gom/change_date.c b/gom/change_date.c index bf51134..14db874 100644 --- a/gom/change_date.c +++ b/gom/change_date.c @@ -92,6 +92,14 @@ void change_date_subscribe() def_elt_end); } +void UNREFALLFUNC(change_date)(struct change_date* obj) +{ + if (obj) { + UNREFALLFUNC(note_sub)(obj->note); + UNREFALLFUNC(user_data)(obj->extra); + } +} + void CLEANFUNC(change_date)(struct change_date *chan) { if (chan) { diff --git a/gom/change_date.h b/gom/change_date.h index ac94b76..f0022e4 100644 --- a/gom/change_date.h +++ b/gom/change_date.h @@ -32,6 +32,8 @@ int write_change_date(Gedcom_write_hndl hndl, int parent, struct change_date *chan); DECLARE_SUB_MAKEFUNC(change_date); + +DECLARE_UNREFALLFUNC(change_date); DECLARE_CLEANFUNC(change_date); DECLARE_ADDFUNC2(change_date, note_sub); DECLARE_ADDFUNC2(change_date, user_data); diff --git a/gom/event.c b/gom/event.c index af6e912..b946aa6 100644 --- a/gom/event.c +++ b/gom/event.c @@ -222,6 +222,22 @@ void event_subscribe() sub_evt_caus_start, def_elt_end); } +void UNREFALLFUNC(event)(struct event* obj) +{ + if (obj) { + struct event* runner; + for (runner = obj; runner; runner = runner->next) { + UNREFALLFUNC(place)(runner->place); + UNREFALLFUNC(address)(runner->address); + UNREFALLFUNC(source_citation)(runner->citation); + UNREFALLFUNC(multimedia_link)(runner->mm_link); + UNREFALLFUNC(note_sub)(runner->note); + unref_xref_value(runner->family); + UNREFALLFUNC(user_data)(runner->extra); + } + } +} + void CLEANFUNC(event)(struct event* evt) { if (evt) { diff --git a/gom/event.h b/gom/event.h index aa519cb..65fa967 100644 --- a/gom/event.h +++ b/gom/event.h @@ -39,6 +39,7 @@ int write_events(Gedcom_write_hndl hndl, int parent, EventType evt_type, DECLARE_SUB_MAKEFUNC(event); +DECLARE_UNREFALLFUNC(event); DECLARE_CLEANFUNC(event); DECLARE_ADDFUNC2(event, source_citation); DECLARE_ADDFUNC2(event, multimedia_link); diff --git a/gom/family.c b/gom/family.c index 8389569..9d4a4e5 100644 --- a/gom/family.c +++ b/gom/family.c @@ -73,6 +73,24 @@ void family_subscribe() gedcom_subscribe_to_element(ELT_FAM_SUBM, fam_subm_start, def_elt_end); } +void UNREFALLFUNC(family)(struct family *fam) +{ + if (fam) { + UNREFALLFUNC(event)(fam->event); + unref_xref_value(fam->husband); + unref_xref_value(fam->wife); + UNREFALLFUNC(xref_list)(fam->children); + UNREFALLFUNC(xref_list)(fam->submitters); + UNREFALLFUNC(lds_event)(fam->lds_spouse_sealing); + UNREFALLFUNC(source_citation)(fam->citation); + UNREFALLFUNC(multimedia_link)(fam->mm_link); + UNREFALLFUNC(note_sub)(fam->note); + UNREFALLFUNC(user_ref_number)(fam->ref); + UNREFALLFUNC(change_date)(fam->change_date); + UNREFALLFUNC(user_data)(fam->extra); + } +} + void CLEANFUNC(family)(struct family* fam) { if (fam) { diff --git a/gom/family_link.c b/gom/family_link.c index cb266b2..cb5435b 100644 --- a/gom/family_link.c +++ b/gom/family_link.c @@ -98,6 +98,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) { @@ -105,6 +115,19 @@ void CLEANFUNC(pedigree)(struct pedigree* ped) } } +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) { diff --git a/gom/family_link.h b/gom/family_link.h index eeb6cd9..bce305f 100644 --- a/gom/family_link.h +++ b/gom/family_link.h @@ -38,6 +38,7 @@ int write_family_links(Gedcom_write_hndl hndl, int parent, LinkType type, DECLARE_SUB_MAKEFUNC(family_link); +DECLARE_UNREFALLFUNC(family_link); DECLARE_CLEANFUNC(family_link); DECLARE_ADDFUNC2(family_link, note_sub); DECLARE_ADDFUNC2(family_link, user_data); diff --git a/gom/func_template.h b/gom/func_template.h index a21424d..872f0ad 100644 --- a/gom/func_template.h +++ b/gom/func_template.h @@ -31,6 +31,7 @@ #define CLEANFUNC(STRUCTTYPE) STRUCTTYPE ## _cleanup #define ADDFUNC(STRUCTTYPE) gom_add_ ## STRUCTTYPE #define SUB_ADDFUNC(STRUCTTYPE) gom_add_ ## STRUCTTYPE +#define UNREFALLFUNC(STRUCTTYPE) STRUCTTYPE ## _unref_all #define DELETEFUNC(STRUCTTYPE) gom_delete_ ## STRUCTTYPE #define SUB_DELETEFUNC(STRUCTTYPE) gom_delete_ ## STRUCTTYPE #define ADDFUNC2(T1,T2) T1 ## _add_ ## T2 @@ -48,6 +49,9 @@ #define DECLARE_CLEANFUNC(STRUCTTYPE) \ void CLEANFUNC(STRUCTTYPE)(struct STRUCTTYPE* obj) +#define DECLARE_UNREFALLFUNC(STRUCTTYPE) \ + void UNREFALLFUNC(STRUCTTYPE)(struct STRUCTTYPE* obj) + #define DECLARE_ADDFUNC2(STRUCTTYPE,T2) \ void ADDFUNC2(STRUCTTYPE,T2)(Gom_ctxt ctxt, struct T2* obj) @@ -145,7 +149,7 @@ } #define DEFINE_DESTROYFUNC(STRUCTTYPE,FIRSTVAL) \ - void CLEANFUNC(STRUCTTYPE)(struct STRUCTTYPE* obj); \ + DECLARE_CLEANFUNC(STRUCTTYPE); \ void DESTROYFUNC(STRUCTTYPE)(struct STRUCTTYPE* obj) { \ if (obj) { \ CLEANFUNC(STRUCTTYPE)(obj); \ @@ -195,15 +199,17 @@ return obj; \ } -/* TODO: Check whether there are still xrefs linked in */ #define DEFINE_DELETEFUNC(STRUCTTYPE) \ + DECLARE_UNREFALLFUNC(STRUCTTYPE); \ int DELETEFUNC(STRUCTTYPE)(struct STRUCTTYPE* obj) \ { \ int result = 1; \ if (obj) { \ result = gedcom_delete_xref(obj->xrefstr); \ - if (result == 0) \ + if (result == 0) { \ + UNREFALLFUNC(STRUCTTYPE)(obj); \ DESTROYFUNC(STRUCTTYPE)(obj); \ + } \ } \ return result; \ } @@ -213,6 +219,7 @@ { \ int result = 1; \ if (obj && *obj) { \ + UNREFALLFUNC(STRUCTTYPE)(*obj); \ CLEANFUNC(STRUCTTYPE)(*obj); \ SAFE_FREE(*obj); \ result = 0; \ diff --git a/gom/gom_internal.h b/gom/gom_internal.h index 910e156..1def3f9 100644 --- a/gom/gom_internal.h +++ b/gom/gom_internal.h @@ -76,6 +76,7 @@ void gom_cast_error(const char* file, int line, void gom_no_context(const char* file, int line); void gom_unexpected_context(const char* file, int line, OBJ_TYPE found); void gom_xref_already_in_use(const char *xrefstr); +void unref_xref_value(struct xref_value *xref); int gom_write_xref_list(Gedcom_write_hndl hndl, Gedcom_elt elt, int tag, int parent_rec_or_elt, @@ -118,6 +119,7 @@ void NULL_DESTROY(void* anything); #include "func_template.h" +DECLARE_UNREFALLFUNC(xref_list); DECLARE_CLEANFUNC(xref_list); #endif /* __GOM_INTERNAL_H */ diff --git a/gom/gom_modify.c b/gom/gom_modify.c index b876a9e..11db4d7 100644 --- a/gom/gom_modify.c +++ b/gom/gom_modify.c @@ -79,6 +79,23 @@ char* gom_set_string_for_locale(char** data, const char* locale_str) return result; } +void unref_xref_value(struct xref_value *xref) +{ + if (xref) + gedcom_unlink_xref(xref->type, xref->string); +} + +void UNREFALLFUNC(xref_list)(struct xref_list* obj) +{ + if (obj) { + struct xref_list* runner; + for (runner = obj; runner; runner = runner->next) { + unref_xref_value(runner->xref); + UNREFALLFUNC(user_data)(runner->extra); + } + } +} + void CLEANFUNC(xref_list)(struct xref_list *obj) { if (obj) { diff --git a/gom/individual.c b/gom/individual.c index 103ad31..b9652ef 100644 --- a/gom/individual.c +++ b/gom/individual.c @@ -102,6 +102,29 @@ void individual_add_family_link(Gom_ctxt ctxt, int ctxt_type, } } +void UNREFALLFUNC(individual)(struct individual *obj) +{ + if (obj) { + UNREFALLFUNC(personal_name)(obj->name); + UNREFALLFUNC(event)(obj->event); + UNREFALLFUNC(event)(obj->attribute); + UNREFALLFUNC(lds_event)(obj->lds_individual_ordinance); + UNREFALLFUNC(family_link)(obj->child_to_family); + UNREFALLFUNC(family_link)(obj->spouse_to_family); + UNREFALLFUNC(xref_list)(obj->submitters); + UNREFALLFUNC(association)(obj->association); + UNREFALLFUNC(xref_list)(obj->alias); + UNREFALLFUNC(xref_list)(obj->ancestor_interest); + UNREFALLFUNC(xref_list)(obj->descendant_interest); + UNREFALLFUNC(source_citation)(obj->citation); + UNREFALLFUNC(multimedia_link)(obj->mm_link); + UNREFALLFUNC(note_sub)(obj->note); + UNREFALLFUNC(user_ref_number)(obj->ref); + UNREFALLFUNC(change_date)(obj->change_date); + UNREFALLFUNC(user_data)(obj->extra); + } +} + void CLEANFUNC(individual)(struct individual* indiv) { if (indiv) { diff --git a/gom/lds_event.c b/gom/lds_event.c index 8587b11..6a7be35 100644 --- a/gom/lds_event.c +++ b/gom/lds_event.c @@ -106,6 +106,19 @@ void lds_event_subscribe() sub_lds_event_famc_start, def_elt_end); } +void UNREFALLFUNC(lds_event)(struct lds_event* obj) +{ + if (obj) { + struct lds_event* runner; + for (runner = obj; runner; runner = runner->next) { + unref_xref_value(runner->family); + UNREFALLFUNC(source_citation)(runner->citation); + UNREFALLFUNC(note_sub)(runner->note); + UNREFALLFUNC(user_data)(runner->extra); + } + } +} + void CLEANFUNC(lds_event)(struct lds_event* lds) { if (lds) { diff --git a/gom/lds_event.h b/gom/lds_event.h index f49e2ee..68eb486 100644 --- a/gom/lds_event.h +++ b/gom/lds_event.h @@ -34,6 +34,7 @@ int write_lds_events(Gedcom_write_hndl hndl, int parent, DECLARE_SUB_MAKEFUNC(lds_event); +DECLARE_UNREFALLFUNC(lds_event); DECLARE_CLEANFUNC(lds_event); DECLARE_ADDFUNC2(lds_event, note_sub); DECLARE_ADDFUNC2(lds_event, source_citation); diff --git a/gom/multimedia.c b/gom/multimedia.c index 38ffa3f..9dbf90b 100644 --- a/gom/multimedia.c +++ b/gom/multimedia.c @@ -77,6 +77,17 @@ void multimedia_subscribe() gedcom_subscribe_to_element(ELT_OBJE_OBJE, obje_obje_start, def_elt_end); } +void UNREFALLFUNC(multimedia)(struct multimedia *obj) +{ + if (obj) { + UNREFALLFUNC(note_sub)(obj->note); + unref_xref_value(obj->continued); + UNREFALLFUNC(user_ref_number)(obj->ref); + UNREFALLFUNC(change_date)(obj->change_date); + UNREFALLFUNC(user_data)(obj->extra); + } +} + void CLEANFUNC(multimedia)(struct multimedia* obj) { if (obj) { diff --git a/gom/multimedia_link.c b/gom/multimedia_link.c index 0b1c4eb..44e9a2d 100644 --- a/gom/multimedia_link.c +++ b/gom/multimedia_link.c @@ -100,6 +100,18 @@ void multimedia_link_subscribe() sub_obje_file_start, def_elt_end); } +void UNREFALLFUNC(multimedia_link)(struct multimedia_link* obj) +{ + if (obj) { + struct multimedia_link* runner; + for (runner = obj; runner; runner = runner->next) { + unref_xref_value(runner->reference); + UNREFALLFUNC(note_sub)(runner->note); + UNREFALLFUNC(user_data)(runner->extra); + } + } +} + void CLEANFUNC(multimedia_link)(struct multimedia_link* mm) { if (mm) { diff --git a/gom/multimedia_link.h b/gom/multimedia_link.h index 9503449..ec2ec6d 100644 --- a/gom/multimedia_link.h +++ b/gom/multimedia_link.h @@ -34,6 +34,7 @@ int write_multimedia_links(Gedcom_write_hndl hndl, int parent, DECLARE_SUB_MAKEFUNC(multimedia_link); +DECLARE_UNREFALLFUNC(multimedia_link); DECLARE_CLEANFUNC(multimedia_link); DECLARE_ADDFUNC2(multimedia_link, note_sub); DECLARE_ADDFUNC2(multimedia_link, user_data); diff --git a/gom/note.c b/gom/note.c index 3c8bc69..6d0dc8a 100644 --- a/gom/note.c +++ b/gom/note.c @@ -85,6 +85,16 @@ void note_subscribe() gedcom_subscribe_to_element(ELT_SUB_CONC, sub_cont_conc_start, def_elt_end); } +void UNREFALLFUNC(note)(struct note *obj) +{ + if (obj) { + UNREFALLFUNC(source_citation)(obj->citation); + UNREFALLFUNC(user_ref_number)(obj->ref); + UNREFALLFUNC(change_date)(obj->change_date); + UNREFALLFUNC(user_data)(obj->extra); + } +} + void CLEANFUNC(note)(struct note* note) { if (note) { diff --git a/gom/note_sub.c b/gom/note_sub.c index 2d748a6..2ff76db 100644 --- a/gom/note_sub.c +++ b/gom/note_sub.c @@ -122,6 +122,18 @@ void note_sub_subscribe() gedcom_subscribe_to_element(ELT_SUB_NOTE, sub_note_start, sub_note_end); } +void UNREFALLFUNC(note_sub)(struct note_sub* obj) +{ + if (obj) { + struct note_sub* runner; + for (runner = obj; runner; runner = runner->next) { + unref_xref_value(runner->reference); + UNREFALLFUNC(source_citation)(runner->citation); + UNREFALLFUNC(user_data)(runner->extra); + } + } +} + void CLEANFUNC(note_sub)(struct note_sub* note) { if (note) { diff --git a/gom/note_sub.h b/gom/note_sub.h index c78bfa2..f47060e 100644 --- a/gom/note_sub.h +++ b/gom/note_sub.h @@ -32,6 +32,7 @@ int write_note_subs(Gedcom_write_hndl hndl, int parent, struct note_sub* note); DECLARE_SUB_MAKEFUNC(note_sub); +DECLARE_UNREFALLFUNC(note_sub); DECLARE_CLEANFUNC(note_sub); DECLARE_ADDFUNC2(note_sub, source_citation); DECLARE_ADDFUNC2(note_sub, user_data); diff --git a/gom/personal_name.c b/gom/personal_name.c index 3b6bb8e..18f3efb 100644 --- a/gom/personal_name.c +++ b/gom/personal_name.c @@ -91,6 +91,18 @@ void name_subscribe() def_elt_end); } +void UNREFALLFUNC(personal_name)(struct personal_name* obj) +{ + if (obj) { + struct personal_name* runner; + for (runner = obj; runner; runner = runner->next) { + UNREFALLFUNC(source_citation)(runner->citation); + UNREFALLFUNC(note_sub)(runner->note); + UNREFALLFUNC(user_data)(runner->extra); + } + } +} + void CLEANFUNC(personal_name)(struct personal_name* name) { if (name) { diff --git a/gom/personal_name.h b/gom/personal_name.h index 24ce27d..c8e7661 100644 --- a/gom/personal_name.h +++ b/gom/personal_name.h @@ -32,6 +32,8 @@ int write_names(Gedcom_write_hndl hndl, int parent, struct personal_name *name); DECLARE_SUB_MAKEFUNC(personal_name); + +DECLARE_UNREFALLFUNC(personal_name); DECLARE_CLEANFUNC(personal_name); DECLARE_ADDFUNC2(personal_name, source_citation); DECLARE_ADDFUNC2(personal_name, note_sub); diff --git a/gom/place.c b/gom/place.c index cb85253..371e2e3 100644 --- a/gom/place.c +++ b/gom/place.c @@ -88,6 +88,15 @@ void place_subscribe() sub_place_form_start, def_elt_end); } +void UNREFALLFUNC(place)(struct place* obj) +{ + if (obj) { + UNREFALLFUNC(source_citation)(obj->citation); + UNREFALLFUNC(note_sub)(obj->note); + UNREFALLFUNC(user_data)(obj->extra); + } +} + void CLEANFUNC(place)(struct place* place) { if (place) { diff --git a/gom/place.h b/gom/place.h index 614dacb..e73d924 100644 --- a/gom/place.h +++ b/gom/place.h @@ -32,6 +32,7 @@ int write_place(Gedcom_write_hndl hndl, int parent, struct place* place); DECLARE_SUB_MAKEFUNC(place); +DECLARE_UNREFALLFUNC(place); DECLARE_CLEANFUNC(place); DECLARE_ADDFUNC2(place, source_citation); DECLARE_ADDFUNC2(place, note_sub); diff --git a/gom/repository.c b/gom/repository.c index 9d383fa..57c6f28 100644 --- a/gom/repository.c +++ b/gom/repository.c @@ -58,6 +58,17 @@ void repository_subscribe() gedcom_subscribe_to_element(ELT_REPO_NAME, repo_name_start, def_elt_end); } +void UNREFALLFUNC(repository)(struct repository *obj) +{ + if (obj) { + UNREFALLFUNC(address)(obj->address); + UNREFALLFUNC(note_sub)(obj->note); + UNREFALLFUNC(user_ref_number)(obj->ref); + UNREFALLFUNC(change_date)(obj->change_date); + UNREFALLFUNC(user_data)(obj->extra); + } +} + void CLEANFUNC(repository)(struct repository* repo) { if (repo) { diff --git a/gom/source.c b/gom/source.c index c13acb3..51c0335 100644 --- a/gom/source.c +++ b/gom/source.c @@ -95,6 +95,22 @@ void source_add_note_to_repo(Gom_ctxt ctxt, struct note_sub* note) LINK_CHAIN_ELT(note_sub, sour->repository.note, note); } +void UNREFALLFUNC(source)(struct source *obj) +{ + if (obj) { + UNREFALLFUNC(source_event)(obj->data.event); + UNREFALLFUNC(note_sub)(obj->data.note); + unref_xref_value(obj->repository.link); + UNREFALLFUNC(note_sub)(obj->repository.note); + UNREFALLFUNC(source_description)(obj->repository.description); + UNREFALLFUNC(multimedia_link)(obj->mm_link); + UNREFALLFUNC(note_sub)(obj->note); + UNREFALLFUNC(user_ref_number)(obj->ref); + UNREFALLFUNC(change_date)(obj->change_date); + UNREFALLFUNC(user_data)(obj->extra); + } +} + void CLEANFUNC(source)(struct source* sour) { if (sour) { diff --git a/gom/source_citation.c b/gom/source_citation.c index c79efcc..64ad42b 100644 --- a/gom/source_citation.c +++ b/gom/source_citation.c @@ -166,6 +166,15 @@ void citation_subscribe() def_elt_end); } +void UNREFALLFUNC(text)(struct text* obj) +{ + if (obj) { + struct text* runner; + for (runner = obj; runner; runner = runner->next) + UNREFALLFUNC(user_data)(runner->extra); + } +} + void CLEANFUNC(text)(struct text* t) { if (t) { @@ -173,6 +182,20 @@ void CLEANFUNC(text)(struct text* t) } } +void UNREFALLFUNC(source_citation)(struct source_citation* obj) +{ + if (obj) { + struct source_citation* runner; + for (runner = obj; runner; runner = runner->next) { + unref_xref_value(runner->reference); + UNREFALLFUNC(text)(runner->text); + UNREFALLFUNC(multimedia_link)(runner->mm_link); + UNREFALLFUNC(note_sub)(runner->note); + UNREFALLFUNC(user_data)(runner->extra); + } + } +} + void CLEANFUNC(source_citation)(struct source_citation* cit) { if (cit) { diff --git a/gom/source_citation.h b/gom/source_citation.h index 0689551..21fb52f 100644 --- a/gom/source_citation.h +++ b/gom/source_citation.h @@ -34,6 +34,7 @@ int write_citations(Gedcom_write_hndl hndl, int parent, DECLARE_SUB_MAKEFUNC(source_citation); +DECLARE_UNREFALLFUNC(source_citation); DECLARE_CLEANFUNC(source_citation); DECLARE_ADDFUNC2(source_citation, note_sub); DECLARE_ADDFUNC2(source_citation, multimedia_link); diff --git a/gom/source_description.c b/gom/source_description.c index 87f34ab..71bd9e8 100644 --- a/gom/source_description.c +++ b/gom/source_description.c @@ -75,6 +75,16 @@ void source_description_subscribe() sub_sour_caln_medi_start, def_elt_end); } +void UNREFALLFUNC(source_description)(struct source_description* obj) +{ + if (obj) { + struct source_description* runner; + for (runner = obj; runner; runner = runner->next) { + UNREFALLFUNC(user_data)(runner->extra); + } + } +} + void CLEANFUNC(source_description)(struct source_description* desc) { if (desc) { diff --git a/gom/source_description.h b/gom/source_description.h index 1ff5441..ce1802f 100644 --- a/gom/source_description.h +++ b/gom/source_description.h @@ -34,6 +34,7 @@ int write_source_descriptions(Gedcom_write_hndl hndl, int parent, DECLARE_SUB_MAKEFUNC(source_description); +DECLARE_UNREFALLFUNC(source_description); DECLARE_CLEANFUNC(source_description); DECLARE_ADDFUNC2(source_description, user_data); diff --git a/gom/source_event.c b/gom/source_event.c index 02882dc..6e353b9 100644 --- a/gom/source_event.c +++ b/gom/source_event.c @@ -78,6 +78,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) { diff --git a/gom/source_event.h b/gom/source_event.h index 7d86a6e..549281c 100644 --- a/gom/source_event.h +++ b/gom/source_event.h @@ -33,6 +33,7 @@ int write_source_events(Gedcom_write_hndl hndl, int parent, DECLARE_SUB_MAKEFUNC(source_event); +DECLARE_UNREFALLFUNC(source_event); DECLARE_CLEANFUNC(source_event); DECLARE_ADDFUNC2(source_event, user_data); diff --git a/gom/submission.c b/gom/submission.c index 3ecee29..3aed081 100644 --- a/gom/submission.c +++ b/gom/submission.c @@ -55,7 +55,15 @@ void submission_subscribe() gedcom_subscribe_to_element(ELT_SUBN_RIN, subn_rin_start, def_elt_end); } -void submission_cleanup() +void UNREFALLFUNC(submission)() +{ + if (gom_submission) { + unref_xref_value(gom_submission->submitter); + UNREFALLFUNC(user_data)(gom_submission->extra); + } +} + +void CLEANFUNC(submission)() { if (gom_submission) { SAFE_FREE(gom_submission->xrefstr); @@ -66,7 +74,6 @@ void submission_cleanup() SAFE_FREE(gom_submission->ordinance_process_flag); SAFE_FREE(gom_submission->record_id); DESTROY_CHAIN_ELTS(user_data, gom_submission->extra); - SAFE_FREE(gom_submission); } } @@ -95,8 +102,7 @@ void DESTROYFUNC(submission)() { if (gom_submission) { submission_cleanup(); - free(gom_submission); - gom_submission = NULL; + SAFE_FREE(gom_submission); } } @@ -127,8 +133,10 @@ int DELETEFUNC(submission)() int result = 1; if (gom_submission) { result = gedcom_delete_xref(gom_submission->xrefstr); - if (result == 0) + if (result == 0) { + UNREFALLFUNC(submission)(); DESTROYFUNC(submission)(); + } } return result; } diff --git a/gom/submitter.c b/gom/submitter.c index 29de511..06376b2 100644 --- a/gom/submitter.c +++ b/gom/submitter.c @@ -91,6 +91,16 @@ void submitter_subscribe() gedcom_subscribe_to_element(ELT_SUBM_RIN, subm_rin_start, def_elt_end); } +void UNREFALLFUNC(submitter)(struct submitter *obj) +{ + if (obj) { + UNREFALLFUNC(address)(obj->address); + UNREFALLFUNC(multimedia_link)(obj->mm_link); + UNREFALLFUNC(change_date)(obj->change_date); + UNREFALLFUNC(user_data)(obj->extra); + } +} + void CLEANFUNC(submitter)(struct submitter* rec) { if (rec) { diff --git a/gom/user_rec.c b/gom/user_rec.c index 90ffb0b..a685f3d 100644 --- a/gom/user_rec.c +++ b/gom/user_rec.c @@ -247,6 +247,15 @@ void user_rec_subscribe() gedcom_subscribe_to_element(ELT_USER, user_elt_start, def_elt_end); } +void UNREFALLFUNC(user_data)(struct user_data *obj) +{ + if (obj) { + struct user_data* runner; + for (runner = obj; runner; runner = runner->next) + unref_xref_value(runner->xref_value); + } +} + void CLEANFUNC(user_data)(struct user_data* data) { if (data) { @@ -255,6 +264,14 @@ void CLEANFUNC(user_data)(struct user_data* data) } } +void UNREFALLFUNC(user_rec)(struct user_rec *obj) +{ + if (obj) { + unref_xref_value(obj->xref_value); + UNREFALLFUNC(user_data)(obj->extra); + } +} + void CLEANFUNC(user_rec)(struct user_rec* rec) { if (rec) { diff --git a/gom/user_rec.h b/gom/user_rec.h index 58f055e..071e2ec 100644 --- a/gom/user_rec.h +++ b/gom/user_rec.h @@ -35,6 +35,7 @@ int write_user_data(Gedcom_write_hndl hndl, struct user_data* data); DECLARE_MAKEFUNC(user_rec); DECLARE_ADDFUNC2(user_rec, user_data); +DECLARE_UNREFALLFUNC(user_data); DECLARE_CLEANFUNC(user_data); #endif /* __USER_REC_H */ diff --git a/gom/user_ref.c b/gom/user_ref.c index c9440ab..2c08e3a 100644 --- a/gom/user_ref.c +++ b/gom/user_ref.c @@ -123,6 +123,15 @@ void user_ref_subscribe() def_elt_end); } +void UNREFALLFUNC(user_ref_number)(struct user_ref_number* obj) +{ + if (obj) { + struct user_ref_number* runner; + for (runner = obj; runner; runner = runner->next) + UNREFALLFUNC(user_data)(runner->extra); + } +} + void CLEANFUNC(user_ref_number)(struct user_ref_number* refn) { if (refn) { diff --git a/gom/user_ref.h b/gom/user_ref.h index 8246d8b..c7c2878 100644 --- a/gom/user_ref.h +++ b/gom/user_ref.h @@ -33,6 +33,7 @@ int write_user_refs(Gedcom_write_hndl hndl, int parent, DECLARE_SUB_MAKEFUNC(user_ref_number); +DECLARE_UNREFALLFUNC(user_ref_number); DECLARE_CLEANFUNC(user_ref_number); DECLARE_ADDFUNC2(user_ref_number, user_data); -- 2.30.2