[squid-dev] [PATCH] turn mempools' delete(nullptr) into NOP

Kinkie gkinkie at gmail.com
Tue Sep 29 19:33:16 UTC 2015


Hi,
  while checking the mempools code during the discussion of thread
"[PATCH] Refactor htcpDetail into MEMPROXY_CLASS" I found out that
mempools' operator delete has a different behavior than that of
::delete.
In particular, ::delete(nullptr) is defined to be a NOP [1]. Our code
instead aborts:
MEMPROXY_CLASS's delete calls MemAllocatorProxy::freeOne which calls
MemImplementingAllocator::freeOne (via MemAllocator) which asserts on
nullptr.

The assert is needed because which freeOne calls
MemAllocator::deallocate which is virtual, specialized by
MemPoolChunked and MemPoolMalloc, neither of which can accept
nullptr's in the general case.
The whole setup is right now working because the API makes it a
responsiblity of the caller never to delete(nullptr).

In the thread I mentioned above, Amos suggests to change our
user-facing API to match ::delete. This patch does exactly that, by
accepting but not processing nullptrs in
MemImplementingAllocator::freeOne.

[1] http://stackoverflow.com/questions/6731331/is-it-still-safe-to-delete-nullptr-in-c0x

-- 
    Francesco
-------------- next part --------------
A non-text attachment was scrubbed...
Name: memproxy-class-allow-delete-nullptr.patch
Type: text/x-diff
Size: 2458 bytes
Desc: not available
URL: <http://lists.squid-cache.org/pipermail/squid-dev/attachments/20150929/994ca10f/attachment.patch>


More information about the squid-dev mailing list