From e7bd7d00b3f3c3f778ac212190e938d9d2af3963 Mon Sep 17 00:00:00 2001 From: krangelov Date: Sun, 8 Aug 2021 16:20:41 +0200 Subject: [PATCH] remove the newly created .ngf on error. --- src/runtime/c/pgf.cxx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/runtime/c/pgf.cxx b/src/runtime/c/pgf.cxx index e0d694cae..58bc513f2 100644 --- a/src/runtime/c/pgf.cxx +++ b/src/runtime/c/pgf.cxx @@ -84,8 +84,10 @@ PgfPGF *pgf_boot_ngf(const char* pgf_path, const char* ngf_path, PgfExn* err) err->msg = strdup(e.what()); } - if (pgf != NULL) + if (pgf != NULL) { delete pgf; + remove(ngf_path); + } return NULL; } @@ -97,10 +99,13 @@ PgfPGF *pgf_read_ngf(const char *fpath, PgfExn* err) pgf_exn_clear(err); + bool is_new = false; try { pgf = new PgfPGF(fpath, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); if (DB::get_root() == 0) { + is_new = true; + DB_scope scope(pgf, WRITER_SCOPE); ref root = DB::malloc(); @@ -123,8 +128,11 @@ PgfPGF *pgf_read_ngf(const char *fpath, PgfExn* err) err->msg = strdup(e.what()); } - if (pgf != NULL) + if (pgf != NULL) { delete pgf; + if (is_new) + remove(ngf_path); + } return NULL; }