From a8124c137e2bfa3605dacadfe469ea22934b4cb3 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Tue, 30 Aug 2016 14:49:47 +0200 Subject: [PATCH] Fixed memory bug in write_smt2 --- backends/smt2/smt2.cc | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/backends/smt2/smt2.cc b/backends/smt2/smt2.cc index 1885cf59a..9668a6425 100644 --- a/backends/smt2/smt2.cc +++ b/backends/smt2/smt2.cc @@ -43,7 +43,25 @@ struct Smt2Worker std::map> fcache; std::map memarrays; std::map bvsizes; - std::vector ids; + dict ids; + + const char *get_id(IdString n) + { + if (ids.count(n) == 0) { + std::string str = log_id(n); + for (int i = 0; i < GetSize(str); i++) { + if (str[i] == '\\') + str[i] = '/'; + } + ids[n] = strdup(str.c_str()); + } + return ids[n]; + } + + template + const char *get_id(T *obj) { + return get_id(obj->name); + } Smt2Worker(RTLIL::Module *module, bool bvmode, bool memmode, bool wiresmode, bool verbose) : ct(module->design), sigmap(module), module(module), bvmode(bvmode), memmode(memmode), @@ -68,15 +86,11 @@ struct Smt2Worker } } - const char *get_id(IdString n) + ~Smt2Worker() { - std::string str = log_id(n); - for (int i = 0; i < GetSize(str); i++) { - if (str[i] == '\\') - str[i] = '/'; - } - ids.push_back(str); - return ids.back().c_str(); + for (auto &it : ids) + free(it.second); + ids.clear(); } const char *get_id(Module *m) -- 2.30.2