public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][_Hashtable] Add missing destructor call
@ 2023-11-06 21:38 François Dumont
  2023-11-06 21:58 ` Sam James
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: François Dumont @ 2023-11-06 21:38 UTC (permalink / raw)
  To: libstdc++; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 558 bytes --]

Noticed looking for other occasion to replace __try/__catch with RAII 
helper.

     libstdc++: [_Hashtable] Add missing node destructor call

     libstdc++-v3/ChangeLog:

             * include/bits/hashtable_policy.h
             (_Hashtable_alloc<>::_M_allocate_node): Add missing call to 
node destructor
             on construct exception.

Tested under Linux x64, ok to commit ?

I hope gmail appli will appreciate .diff instead of .patch. .txt are not 
in .gitignore so annoying to use for patches.

François

[-- Attachment #2: hashtable_policy.h.diff --]
[-- Type: text/x-patch, Size: 1097 bytes --]

diff --git a/libstdc++-v3/include/bits/hashtable_policy.h b/libstdc++-v3/include/bits/hashtable_policy.h
index 2d13bda6ae0..ed2b2c02a4a 100644
--- a/libstdc++-v3/include/bits/hashtable_policy.h
+++ b/libstdc++-v3/include/bits/hashtable_policy.h
@@ -2020,19 +2020,20 @@ namespace __detail
       _Hashtable_alloc<_NodeAlloc>::_M_allocate_node(_Args&&... __args)
       -> __node_ptr
       {
-	auto __nptr = __node_alloc_traits::allocate(_M_node_allocator(), 1);
+	auto& __alloc = _M_node_allocator();
+	auto __nptr = __node_alloc_traits::allocate(__alloc, 1);
 	__node_ptr __n = std::__to_address(__nptr);
 	__try
 	  {
 	    ::new ((void*)__n) __node_type;
-	    __node_alloc_traits::construct(_M_node_allocator(),
-					   __n->_M_valptr(),
+	    __node_alloc_traits::construct(__alloc, __n->_M_valptr(),
 					   std::forward<_Args>(__args)...);
 	    return __n;
 	  }
 	__catch(...)
 	  {
-	    __node_alloc_traits::deallocate(_M_node_allocator(), __nptr, 1);
+	    __n->~__node_type();
+	    __node_alloc_traits::deallocate(__alloc, __nptr, 1);
 	    __throw_exception_again;
 	  }
       }

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-11-08 14:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-06 21:38 [PATCH][_Hashtable] Add missing destructor call François Dumont
2023-11-06 21:58 ` Sam James
2023-11-06 23:13 ` Jonathan Wakely
2023-11-06 23:28 ` Jonathan Wakely
2023-11-08  5:39   ` François Dumont
2023-11-08 14:26     ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).