summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/backward
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@google.com>2011-05-25 23:09:14 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2011-05-25 23:09:14 +0000
commit2b4e07b814b50a6f5cdf6b10d05117623d8854c9 (patch)
treec4e6283a51cca060e1f1e57da5f033aa3fced142 /libstdc++-v3/include/backward
parent48126bcbc276e1684f96f7c087d69688028cae73 (diff)
downloadgcc-2b4e07b814b50a6f5cdf6b10d05117623d8854c9.tar.gz
re PR libstdc++/49060 (use of deleted memory in __gnu_cxx::hashtable::erase)
PR libstdc++/49060 * include/backward/hashtable.h (hashtable::erase): Don't crash if erasing first and another element with a reference to the other element. * testsuite/backward/hash_set/49060.cc: New. From-SVN: r174240
Diffstat (limited to 'libstdc++-v3/include/backward')
-rw-r--r--libstdc++-v3/include/backward/hashtable.h15
1 files changed, 8 insertions, 7 deletions
diff --git a/libstdc++-v3/include/backward/hashtable.h b/libstdc++-v3/include/backward/hashtable.h
index 0bcaec4fdc2..91b0c602cec 100644
--- a/libstdc++-v3/include/backward/hashtable.h
+++ b/libstdc++-v3/include/backward/hashtable.h
@@ -898,13 +898,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__next = __cur->_M_next;
}
}
- if (_M_equals(_M_get_key(__first->_M_val), __key))
- {
- _M_buckets[__n] = __first->_M_next;
- _M_delete_node(__first);
- ++__erased;
- --_M_num_elements;
- }
+ bool __delete_first = _M_equals(_M_get_key(__first->_M_val), __key);
if (__saved_slot)
{
__next = __saved_slot->_M_next;
@@ -913,6 +907,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
++__erased;
--_M_num_elements;
}
+ if (__delete_first)
+ {
+ _M_buckets[__n] = __first->_M_next;
+ _M_delete_node(__first);
+ ++__erased;
+ --_M_num_elements;
+ }
}
return __erased;
}