Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: now/nmc
base: 06b19a7920
...
head fork: now/nmc
compare: a1155d5242
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
Commits on Aug 28, 2012
Nikolai Weibull Add valgrind support 5291935
Nikolai Weibull Free all unfreed memory (pass valgrind checks) a1155d5
View
9 Makefile.am
@@ -53,6 +53,15 @@ $(TESTSUITE): $(testdir)/testsuite.at $(testdir)/package.m4 $(TESTSUITE_AT)
$(AUTOTEST) -I '$(testdir)' -o $@.tmp $@.at
mv $@.tmp $@
+.PHONY: maintainer-check-valgrind
+maintainer-check-valgrind: $(BUILT_SOURCES) all-am $(testdir)/atconfig $(testdir)/atlocal $(TESTSUITE)
+ test -z '$(VALGRIND)' || \
+ VALGRIND_OPTS='--leak-check=full --show-reachable=yes' \
+ $(SHELL) '$(TESTSUITE)' -C '$(testdir)' $(TESTSUITEFLAGS) PRENMC='$(VALGRIND) -q'
+
+.PHONY: maintainer-check
+maintainer-check: maintainer-check-valgrind
+
EXTRA_DIST = \
$(testdir)/atlocal.in \
$(testdir)/package.m4 \
View
1  configure.ac
@@ -62,6 +62,7 @@ if test "${enableval}" = yes; then
fi
AC_PROG_YACC
+AC_CHECK_PROGS([VALGRIND], [valgrind])
PKG_CHECK_MODULES([XML], [libxml-2.0])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([
View
38 src/grammar.y
@@ -11,6 +11,9 @@
#include "nmc.h"
#include "parser.h"
+extern void nmc_grammar_initialize(void);
+extern void nmc_grammar_finalize(void);
+
typedef xmlNodePtr (*definefn)(const xmlChar *, regmatch_t *);
struct definition
@@ -36,7 +39,7 @@ definition_free(xmlLinkPtr link)
{
struct definition *definition = (struct definition *)xmlLinkGetData(link);
regfree(&definition->regex);
- xmlFree(definition);
+ nmc_free(definition);
}
static xmlNodePtr
@@ -69,8 +72,8 @@ ref(const xmlChar *buffer, regmatch_t *matches)
(const char *[]){ "title", "uri", NULL });
}
-static void
-initialize_definitions(void)
+void
+nmc_grammar_initialize(void)
{
if (definitions != NULL)
return;
@@ -79,6 +82,13 @@ initialize_definitions(void)
xmlListPushBack(definitions, definition_new("^(.+) +at +(.+)", ref));
}
+void
+nmc_grammar_finalize(void)
+{
+ if (definitions != NULL)
+ xmlListDelete(definitions);
+}
+
struct footnote_define_closure
{
const xmlChar *buffer;
@@ -128,12 +138,17 @@ footnote_new(YYLTYPE *location, xmlChar *id, xmlBufferPtr buffer)
}
static void
-footnote_free(xmlLinkPtr link)
+footnote_free1(struct footnote *footnote)
{
- struct footnote *footnote = (struct footnote *)xmlLinkGetData(link);
xmlFree(footnote->id);
xmlFreeNode(footnote->node);
- xmlFree(footnote);
+ nmc_free(footnote);
+}
+
+static void
+footnote_free(xmlLinkPtr link)
+{
+ footnote_free1((struct footnote *)xmlLinkGetData(link));
}
struct sigil
@@ -156,7 +171,7 @@ sigil_free(xmlLinkPtr link)
{
struct sigil *sigil = (struct sigil *)xmlLinkGetData(link);
xmlFree(sigil->id);
- xmlFree(sigil);
+ nmc_free(sigil);
}
struct anchor
@@ -183,7 +198,10 @@ anchor_id(struct anchor *anchor)
static void
anchor_free(xmlLinkPtr link)
{
- xmlFree(xmlLinkGetData(link));
+ struct anchor *anchor = (struct anchor *)xmlLinkGetData(link);
+ if (anchor->node->children == NULL)
+ xmlFreeNode(anchor->node);
+ nmc_free(anchor);
}
static int
@@ -275,7 +293,6 @@ node_free(struct nmc_parser *parser, xmlNodePtr node)
%error-verbose
%expect 0
%locations
-%initial-action { initialize_definitions(); }
%token END 0 "end of file"
%token ERROR
@@ -348,7 +365,7 @@ node_free(struct nmc_parser *parser, xmlNodePtr node)
%destructor { xmlBufferFree($$); } <buffer>
%destructor { node_free(parser, $$); } <node>
%destructor { xmlListDelete($$); } <list>
-%destructor { xmlFree($$); } <footnote>
+%destructor { footnote_free1($$); } <footnote>
%code
{
@@ -652,6 +669,7 @@ footnote: FOOTNOTE {
nmc_parser_error(parser, &@$,
"unrecognized footnote content: %s",
xmlBufferContent($1.buffer));
+ xmlBufferFree($1.buffer);
};
paragraph: PARAGRAPH inlines { $$ = wrap("p", $2); };
View
8 src/nmc.c
@@ -10,6 +10,8 @@
#include "parser.h"
extern int nmc_grammar_debug;
+extern void nmc_grammar_initialize(void);
+extern void nmc_grammar_finalize(void);
static int
report_nmc_parser_error(const struct nmc_parser_error *error)
@@ -49,6 +51,8 @@ main(UNUSED(int argc), UNUSED(char **argv))
xmlInitParser();
+ nmc_grammar_initialize();
+
xmlListPtr errors;
xmlDocPtr doc = nmc_parse(BAD_CAST buffer, &errors);
if (!xmlListEmpty(errors))
@@ -61,8 +65,12 @@ main(UNUSED(int argc), UNUSED(char **argv))
xmlFreeDoc(doc);
+ nmc_grammar_finalize();
+
xmlCleanupParser();
+ nmc_free(buffer);
+
return result;
}
View
2  src/nmc.h
@@ -21,4 +21,6 @@
#define nmc_new_n(type, n) (type *)xmlMalloc(sizeof(type) * (n))
+#define nmc_free(value) xmlFree(value)
+
#endif
View
5 src/parser.c
@@ -14,7 +14,10 @@ int nmc_grammar_parse(struct nmc_parser *parser);
static void
error_free(xmlLinkPtr link)
{
- xmlFree(xmlLinkGetData(link));
+ struct nmc_parser_error *error =
+ (struct nmc_parser_error *)xmlLinkGetData(link);
+ nmc_free(error->message);
+ nmc_free(error);
}
void

No commit comments for this range

Something went wrong with that request. Please try again.