[libsigcplusplus/libsigc++-2-10] slot_base::set_parent(): Create a dummy slot_rep if necessary
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsigcplusplus/libsigc++-2-10] slot_base::set_parent(): Create a dummy slot_rep if necessary
- Date: Thu, 9 Nov 2017 08:19:52 +0000 (UTC)
commit a0089c47b0942cf889aaf45e5a5348b6fac644c3
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date: Thu Nov 9 09:13:28 2017 +0100
slot_base::set_parent(): Create a dummy slot_rep if necessary
set_parent() must always store the supplied parent pointer and cleanup
function pointer, or else there may be a memory leak. The pointers are
stored in slot_rep. Bug 167714
sigc++/functors/slot_base.cc | 13 +++++++++++--
1 files changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/sigc++/functors/slot_base.cc b/sigc++/functors/slot_base.cc
index 1b8285a..84b9df7 100644
--- a/sigc++/functors/slot_base.cc
+++ b/sigc++/functors/slot_base.cc
@@ -36,6 +36,14 @@ struct destroy_notify_struct
bool deleted_;
};
+
+// Used by slot_base::set_parent() when a slot_base without a rep_ is assigned a parent.
+class dummy_slot_rep : public sigc::internal::slot_rep
+{
+public:
+ dummy_slot_rep() : slot_rep(nullptr, nullptr, &clone) {}
+ static void* clone(void*) { return new dummy_slot_rep(); }
+};
} // anonymous namespace
namespace sigc
@@ -263,8 +271,9 @@ slot_base& slot_base::operator=(slot_base&& src)
void slot_base::set_parent(void* parent, void* (*cleanup)(void*)) const noexcept
{
- if (rep_)
- rep_->set_parent(parent, cleanup);
+ if (!rep_)
+ rep_ = new dummy_slot_rep();
+ rep_->set_parent(parent, cleanup);
}
void slot_base::add_destroy_notify_callback(void* data, func_destroy_notify func) const
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]