From 743df9f0f943c62835ebd21d31bea68a0395edac Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Tue, 8 Jul 2025 23:53:38 +0000 Subject: [PATCH 1/2] Fix space leak in `SatGen::importSigSpecWorker()` by avoiding `log_id()`. Calling `log_id()` leaks a copy of the ID into `log_id_cache` until the end of the pass, which causes exorbitant memory usage. See issue #5210. --- kernel/satgen.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/satgen.h b/kernel/satgen.h index 8a89ff9db..2c8cbda13 100644 --- a/kernel/satgen.h +++ b/kernel/satgen.h @@ -101,7 +101,9 @@ struct SatGen else vec.push_back(bit == (undef_mode ? RTLIL::State::Sx : RTLIL::State::S1) ? ez->CONST_TRUE : ez->CONST_FALSE); } else { - std::string name = pf + (bit.wire->width == 1 ? stringf("%s", log_id(bit.wire)) : stringf("%s [%d]", log_id(bit.wire->name), bit.offset)); + std::string wire_name = RTLIL::unescape_id(bit.wire->name); + std::string name = pf + + (bit.wire->width == 1 ? wire_name : stringf("%s [%d]", wire_name.c_str(), bit.offset)); vec.push_back(ez->frozen_literal(name)); imported_signals[pf][bit] = vec.back(); } From f34c4f2e26f0e18df7eb3393ec755b5e6c288b00 Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Wed, 9 Jul 2025 16:20:27 +0200 Subject: [PATCH 2/2] log: deduplicate unescape_id from log_id --- kernel/log.cc | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/kernel/log.cc b/kernel/log.cc index fabbe09fd..679a55562 100644 --- a/kernel/log.cc +++ b/kernel/log.cc @@ -664,15 +664,9 @@ const char *log_const(const RTLIL::Const &value, bool autoint) const char *log_id(const RTLIL::IdString &str) { - log_id_cache.push_back(strdup(str.c_str())); - const char *p = log_id_cache.back(); - if (p[0] != '\\') - return p; - if (p[1] == '$' || p[1] == '\\' || p[1] == 0) - return p; - if (p[1] >= '0' && p[1] <= '9') - return p; - return p+1; + std::string unescaped = RTLIL::unescape_id(str); + log_id_cache.push_back(strdup(unescaped.c_str())); + return log_id_cache.back(); } const char *log_str(const char *str)