From 3d4c6031d85158440488d62c90d95cbd22ed664f Mon Sep 17 00:00:00 2001 From: krangelov Date: Thu, 9 Sep 2021 07:20:15 +0200 Subject: [PATCH 1/3] missing call to free after the call to pgf_abstract_name --- src/runtime/c/pgf/namespace.h | 2 +- src/runtime/c/pgf/pgf.h | 3 +++ src/runtime/python/pypgf.c | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/runtime/c/pgf/namespace.h b/src/runtime/c/pgf/namespace.h index 96faab9cd..2a0b2c694 100644 --- a/src/runtime/c/pgf/namespace.h +++ b/src/runtime/c/pgf/namespace.h @@ -287,7 +287,7 @@ Namespace namespace_insert(Namespace map, ref value) return Node::new_node(value,map->left,map->right); } } - + template ref namespace_lookup(Namespace map, PgfText *name) { diff --git a/src/runtime/c/pgf/pgf.h b/src/runtime/c/pgf/pgf.h index d8f2c31d5..7ede7d942 100644 --- a/src/runtime/c/pgf/pgf.h +++ b/src/runtime/c/pgf/pgf.h @@ -247,6 +247,9 @@ void pgf_free(PgfDB *pgf); PGF_API_DECL void pgf_free_revision(PgfDB *pgf, PgfRevision revision); +/* Returns a newly allocated text which contains the abstract name of + * the grammar. The text must be released with a call to free. + */ PGF_API_DECL PgfText *pgf_abstract_name(PgfDB *db, PgfRevision revision, PgfExn* err); diff --git a/src/runtime/python/pypgf.c b/src/runtime/python/pypgf.c index e04ce4076..39baec9ec 100644 --- a/src/runtime/python/pypgf.c +++ b/src/runtime/python/pypgf.c @@ -1777,6 +1777,7 @@ PGF_getAbstractName(PGFObject *self, void *closure) } PyObject *name = PyString_FromStringAndSize(txt->text, txt->size); + free(txt); return name; } From 36ccb7ac8f9b1749f8b58e94b38c715a27bf9655 Mon Sep 17 00:00:00 2001 From: krangelov Date: Thu, 9 Sep 2021 07:22:25 +0200 Subject: [PATCH 2/3] PGF_API -> PGF_API_DECL --- src/runtime/c/pgf/pgf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/c/pgf/pgf.h b/src/runtime/c/pgf/pgf.h index 7ede7d942..8ba239b60 100644 --- a/src/runtime/c/pgf/pgf.h +++ b/src/runtime/c/pgf/pgf.h @@ -324,7 +324,7 @@ PgfRevision pgf_clone_revision(PgfDB *db, PgfRevision revision, PgfText *name, PgfExn *err); -PGF_API +PGF_API_DECL void pgf_commit_revision(PgfDB *db, PgfRevision revision, PgfExn *err); From 0dae265b05f4f263f5db362bc86d0753fbde6d8f Mon Sep 17 00:00:00 2001 From: krangelov Date: Thu, 9 Sep 2021 07:25:57 +0200 Subject: [PATCH 3/3] expand the comment about PgfExn --- src/runtime/c/pgf/pgf.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/runtime/c/pgf/pgf.h b/src/runtime/c/pgf/pgf.h index 8ba239b60..68578e710 100644 --- a/src/runtime/c/pgf/pgf.h +++ b/src/runtime/c/pgf/pgf.h @@ -56,6 +56,9 @@ typedef struct { * from a system call, then type will be PGF_EXN_SYSTEM_ERROR and * the field code will contain the value of errno from the C runtime. * The field msg will be NULL or it may contain a file name. + * The file name will be the same string that was passed when the API + * function was called. This means that the string does not have to + * be freed from the error handling code. * * - If the exception was caused by factors related to the GF runtime * itself, then the error type is PGF_EXN_PGF_ERROR, and the field