diff options
author | ArkadyRudenko <[email protected]> | 2025-05-22 15:12:03 +0300 |
---|---|---|
committer | GitHub <[email protected]> | 2025-05-22 15:12:03 +0300 |
commit | f25d7be4b4c78257c58a785ca5398d57822169eb (patch) | |
tree | b37eb114ab6dc9b34523ecf2aa17f14948273cae | |
parent | 0ecacf995bceb9ec6666a31ffe19e9a97c3afef4 (diff) |
bugfix protobuf_printer: avoid a memory leak (#18653)
-rw-r--r-- | ydb/library/protobuf_printer/protobuf_printer.h | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/ydb/library/protobuf_printer/protobuf_printer.h b/ydb/library/protobuf_printer/protobuf_printer.h index d9487c1cd31..0542cb69e28 100644 --- a/ydb/library/protobuf_printer/protobuf_printer.h +++ b/ydb/library/protobuf_printer/protobuf_printer.h @@ -10,7 +10,13 @@ public: bool RegisterFieldValuePrinters(const google::protobuf::Descriptor* desc, const char* name) { const google::protobuf::FieldDescriptor* field = desc->FindFieldByName(name); Y_ASSERT(field != nullptr); - return RegisterFieldValuePrinter(field, new TPrinter()); + auto printer = std::make_unique<TPrinter>(); + const auto success = RegisterFieldValuePrinter(field, printer.get()); + if (success) { + // RegisterFieldValuePrinter took a ownership of the printer => release it. + printer.release(); + } + return success; } template <class TPrinter, class... T> |