From a5cbf3e894ceae111e4dc8bbe522fcf376d356af Mon Sep 17 00:00:00 2001 From: krangelov Date: Thu, 18 Nov 2021 18:16:41 +0100 Subject: [PATCH] fix other potential allocation failures --- src/runtime/c/pgf/pgf.cxx | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/runtime/c/pgf/pgf.cxx b/src/runtime/c/pgf/pgf.cxx index b21631556..2d172e7d7 100644 --- a/src/runtime/c/pgf/pgf.cxx +++ b/src/runtime/c/pgf/pgf.cxx @@ -1168,13 +1168,20 @@ public: throw pgf_error("Missing linearization category"); } + ref> args = + vector_new(n_prods*absfun->type->hypos->len); + ref>> res = + vector_new>(n_prods); + ref>>> seqs = + vector_new>>(n_prods*lincat->fields->len); + lin = PgfDB::malloc(absfun->name.size+1); memcpy(&lin->name, &absfun->name, sizeof(PgfText)+absfun->name.size+1); lin->ref_count = 1; lin->absfun = absfun; - lin->args = vector_new(n_prods*absfun->type->hypos->len); - lin->res = vector_new>(n_prods); - lin->seqs = vector_new>>(n_prods*lincat->fields->len); + lin->args = args; + lin->res = res; + lin->seqs = seqs; this->arg_index = 0; this->res_index = 0; @@ -1250,7 +1257,8 @@ public: if (seq_index >= lin->seqs->len) throw pgf_error(builder_error_msg); - *vector_elem(lin->seqs, seq_index) = vector_new(n_syms); + ref> syms = vector_new(n_syms); + *vector_elem(lin->seqs, seq_index) = syms; sym_index = 0; } PGF_API_END } @@ -1596,15 +1604,17 @@ void pgf_create_lincat(PgfDB *db, throw pgf_error("There is no corresponding category in the abstract syntax"); } + ref>> db_fields = vector_new>(n_fields); + for (size_t i = 0; i < n_fields; i++) { + ref field = textdup_db(fields[i]); + *vector_elem(db_fields, i) = field; + } + ref lincat = PgfDB::malloc(name->size+1); memcpy(&lincat->name, name, sizeof(PgfText)+name->size+1); lincat->ref_count = 1; lincat->abscat = abscat; - lincat->fields = vector_new>(n_fields); - - for (size_t i = 0; i < n_fields; i++) { - *vector_elem(lincat->fields, i) = textdup_db(fields[i]); - } + lincat->fields = db_fields; Namespace lincats = namespace_insert(concr->lincats, lincat);