[libxml++] Node::remove_child(): Fix a use of deleted memory
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libxml++] Node::remove_child(): Fix a use of deleted memory
- Date: Fri, 11 Feb 2011 15:05:07 +0000 (UTC)
commit 1cc2df4fc006b15fcc08e15f94180a4a5f502ebc
Author: Murray Cumming <murrayc murrayc com>
Date: Fri Feb 11 16:04:59 2011 +0100
Node::remove_child(): Fix a use of deleted memory
* libxml++/nodes/node.cc:
Use a temporary variable to avoid accessing the node C++ instance after we
have deleted it. Valgrind foudn this.
Also remove the comment about the libxml deleting our C++ instance via a
callback, because we don't do that anymore.
ChangeLog | 10 ++++++++++
libxml++/nodes/node.cc | 8 +++++---
2 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 45f72f8..236e272 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2011-02-11 Murray Cumming <murrayc murrayc com>
+
+ Node::remove_child(): Fix a use of deleted memory
+
+ * libxml++/nodes/node.cc:
+ Use a temporary variable to avoid accessing the node C++ instance after we
+ have deleted it. Valgrind foudn this.
+ Also remove the comment about the libxml deleting our C++ instance via a
+ callback, because we don't do that anymore.
+
2010-11-26 Murray Cumming <murrayc murrayc com>
Check some libxml function return values.
diff --git a/libxml++/nodes/node.cc b/libxml++/nodes/node.cc
index cbf1008..e9b5402 100644
--- a/libxml++/nodes/node.cc
+++ b/libxml++/nodes/node.cc
@@ -187,9 +187,11 @@ void Node::remove_child(Node* node)
{
//TODO: Allow a node to be removed without deleting it, to allow it to be moved?
//This would require a more complex memory management API.
- Node::free_wrappers(node->cobj());
- xmlUnlinkNode(node->cobj());
- xmlFreeNode(node->cobj()); //The C++ instance will be deleted in a callback.
+
+ xmlNode* cnode = node->cobj();
+ Node::free_wrappers(cnode); //This delete the C++ node (not this) itself.
+ xmlUnlinkNode(cnode);
+ xmlFreeNode(cnode);
}
Node* Node::import_node(const Node* node, bool recursive)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]