From: simon Date: Thu, 1 Apr 2004 17:01:10 +0000 (+0000) Subject: Fix a couple of memory leaks in backends. X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/halibut/commitdiff_plain/e5e6bf9d1d215fa25484c6d5832eec96dfaa607b Fix a couple of memory leaks in backends. git-svn-id: svn://svn.tartarus.org/sgt/halibut@4016 cda61777-01e9-0310-a592-d414129be87e --- diff --git a/bk_text.c b/bk_text.c index 15a4fc0..df8ae62 100644 --- a/bk_text.c +++ b/bk_text.c @@ -65,17 +65,17 @@ static textconfig text_configure(paragraph *source) { ret.atitle.underline = L'='; ret.achapter.align = LEFT; ret.achapter.just_numbers = FALSE; - ret.achapter.number_suffix = ustrdup(L": "); + ret.achapter.number_suffix = L": "; ret.achapter.underline = L'-'; ret.nasect = 1; ret.asect = mknewa(alignstruct, ret.nasect); ret.asect[0].align = LEFTPLUS; ret.asect[0].just_numbers = TRUE; - ret.asect[0].number_suffix = ustrdup(L" "); + ret.asect[0].number_suffix = L" "; ret.asect[0].underline = L'\0'; ret.include_version_id = TRUE; ret.indent_preambles = FALSE; - ret.bullet.text = ustrdup(L"-"); + ret.bullet.text = L"-"; for (; source; source = source->next) { if (source->type == para_Config) { @@ -96,7 +96,7 @@ static textconfig text_configure(paragraph *source) { } else if (!ustricmp(source->keyword, L"text-chapter-numeric")) { ret.achapter.just_numbers = utob(uadv(source->keyword)); } else if (!ustricmp(source->keyword, L"text-chapter-suffix")) { - ret.achapter.number_suffix = ustrdup(uadv(source->keyword)); + ret.achapter.number_suffix = uadv(source->keyword); } else if (!ustricmp(source->keyword, L"text-section-align")) { wchar_t *p = uadv(source->keyword); int n = 0; @@ -152,11 +152,12 @@ static textconfig text_configure(paragraph *source) { if (n >= ret.nasect) { int i; ret.asect = resize(ret.asect, n+1); - for (i = ret.nasect; i <= n; i++) + for (i = ret.nasect; i <= n; i++) { ret.asect[i] = ret.asect[ret.nasect-1]; + } ret.nasect = n+1; } - ret.asect[n].number_suffix = ustrdup(p); + ret.asect[n].number_suffix = p; } else if (!ustricmp(source->keyword, L"text-title-align")) { ret.atitle.align = utoalign(uadv(source->keyword)); } else if (!ustricmp(source->keyword, L"text-title-underline")) { @@ -330,14 +331,7 @@ void text_backend(paragraph *sourceform, keywordlist *keywords, * Tidy up */ fclose(fp); - { - int i; - sfree(conf.achapter.number_suffix); - for (i = 0; i < conf.nasect; i++) - sfree(conf.asect[i].number_suffix); - sfree(conf.asect); - sfree(conf.bullet.text); - } + sfree(conf.asect); } /* diff --git a/bk_xhtml.c b/bk_xhtml.c index 02e2a32..cba84ed 100644 --- a/bk_xhtml.c +++ b/bk_xhtml.c @@ -144,13 +144,13 @@ static xhtmlconfig xhtml_configure(paragraph *source) ret.suppress_address = FALSE; ret.fchapter.just_numbers = FALSE; - ret.fchapter.number_suffix = ustrdup(L": "); + ret.fchapter.number_suffix = L": "; ret.nfsect = 2; ret.fsect = mknewa(xhtmlheadfmt, ret.nfsect); ret.fsect[0].just_numbers = FALSE; - ret.fsect[0].number_suffix = ustrdup(L": "); + ret.fsect[0].number_suffix = L": "; ret.fsect[1].just_numbers = TRUE; - ret.fsect[1].number_suffix = ustrdup(L" "); + ret.fsect[1].number_suffix = L" "; for (; source; source = source->next) { @@ -199,7 +199,7 @@ static xhtmlconfig xhtml_configure(paragraph *source) } else if (!ustricmp(source->keyword, L"xhtml-chapter-numeric")) { ret.fchapter.just_numbers = utob(uadv(source->keyword)); } else if (!ustricmp(source->keyword, L"xhtml-chapter-suffix")) { - ret.fchapter.number_suffix = ustrdup(uadv(source->keyword)); + ret.fchapter.number_suffix = uadv(source->keyword); } else if (!ustricmp(source->keyword, L"xhtml-section-numeric")) { wchar_t *p = uadv(source->keyword); int n = 0; @@ -229,7 +229,7 @@ static xhtmlconfig xhtml_configure(paragraph *source) ret.fsect[i] = ret.fsect[ret.nfsect-1]; ret.nfsect = n+1; } - ret.fsect[n].number_suffix = ustrdup(p); + ret.fsect[n].number_suffix = p; } } } @@ -676,13 +676,7 @@ void xhtml_backend(paragraph *sourceform, keywordlist *in_keywords, } ientry->backend_data = NULL; } - { - int i; - sfree(conf.fchapter.number_suffix); - for (i = 0; i < conf.nfsect; i++) - sfree(conf.fsect[i].number_suffix); - sfree(conf.fsect); - } + sfree(conf.fsect); } static int xhtml_para_level(paragraph *p)