Remove redundant nullptr checks before deallocation #10696

pull practicalswift wants to merge 1 commits into bitcoin:master from practicalswift:delete-nullptr changing 3 files +3 −6
  1. practicalswift commented at 9:17 PM on June 28, 2017: contributor

    Rationale:

    • delete ptr is a no-op if ptr is nullptr
  2. fanquake added the label Refactoring on Jun 29, 2017
  3. jonasschnelli commented at 6:37 AM on June 29, 2017: contributor

    Is that completely safe? AFAIK the C++03 standard kept deleting a nullptr (NULL) as undefined. Not sure about C++11.

  4. sipa commented at 7:29 AM on June 29, 2017: member

    According to https://stackoverflow.com/questions/25329576/calling-delete-on-null-pointers-c03-vs-c11, C++11 (accidentally?) dropped the requirement that deleting a nullptr is a noop, and C++14 is clearer about it again.

  5. practicalswift commented at 7:51 AM on June 29, 2017: contributor

    Ouch, if I'm mistaken regarding delete NULL being a no-op in C++11. If that is the case I'll instead take a look at all delete:s in the code base to make sure that we are not accidentally doing any potential delete NULL:s.

  6. laanwj commented at 6:28 AM on June 30, 2017: member

    Ouch, if I'm mistaken regarding delete NULL being a no-op in C++11

    We assume universally that delete NULL is a no-op. 99% of actual C++ code out there does so. This is just a language lawyer's argument. No compiler will break that behavior. As it is resolved again for C++14, please don't plow over the entire source code to remove that assumption.

  7. practicalswift commented at 7:29 AM on June 30, 2017: contributor

    @laanwj Yes, that was my assumption from the beginning :-) This PR should be completely safe then and consistent with the assumptions made in the rest of the code base with regards to delete NULL being a no-op.

  8. Remove redundant nullptr checks before deallocation
    Rationale:
    * delete ptr is a no-op if ptr is nullptr
    b109a1c396
  9. practicalswift force-pushed on Aug 14, 2017
  10. practicalswift commented at 3:45 PM on August 14, 2017: contributor

    Rebased!

  11. laanwj merged this on Nov 9, 2017
  12. laanwj closed this on Nov 9, 2017

  13. laanwj referenced this in commit ef3758d1ef on Nov 9, 2017
  14. in src/net.cpp:2756 in b109a1c396
    2752 | @@ -2753,8 +2753,7 @@ CNode::~CNode()
    2753 |  {
    2754 |      CloseSocket(hSocket);
    2755 |  
    2756 | -    if (pfilter)
    2757 | -        delete pfilter;
    2758 | +    delete pfilter;
    


    laanwj commented at 12:40 PM on November 9, 2017:

    BTW as this one is a) in a destructor b) at the end of the destructor, why aren't we using a smart pointer w/ RAII?

  15. practicalswift commented at 3:55 PM on November 9, 2017: contributor

    @laanwj Regarding pfilter RAII – that has already been taken care of in #11043 :-)

  16. TheBlueMatt commented at 11:15 PM on November 11, 2017: member

    post-merge-obvious utACK b109a1c3962a9f45fb5819afd69c7caaf78eb35e

  17. PastaPastaPasta referenced this in commit e7b1a8ce8a on Dec 22, 2019
  18. PastaPastaPasta referenced this in commit 0a9e386810 on Jan 2, 2020
  19. PastaPastaPasta referenced this in commit f3fc91afab on Jan 4, 2020
  20. PastaPastaPasta referenced this in commit da6741bb7a on Jan 12, 2020
  21. PastaPastaPasta referenced this in commit 5b08b195ce on Jan 12, 2020
  22. PastaPastaPasta referenced this in commit 86a6a42fb2 on Jan 12, 2020
  23. PastaPastaPasta referenced this in commit 660d380f81 on Jan 12, 2020
  24. PastaPastaPasta referenced this in commit e932a56a46 on Jan 12, 2020
  25. PastaPastaPasta referenced this in commit 4eb48455ae on Jan 12, 2020
  26. PastaPastaPasta referenced this in commit bfa7f69dd3 on Jan 16, 2020
  27. PastaPastaPasta referenced this in commit 3bae57af8d on Jan 22, 2020
  28. PastaPastaPasta referenced this in commit 2ab2efc5a8 on Jan 29, 2020
  29. PastaPastaPasta referenced this in commit 22cbe2c74e on Jan 29, 2020
  30. ckti referenced this in commit 07200c2191 on Mar 28, 2021
  31. practicalswift deleted the branch on Apr 10, 2021
  32. gades referenced this in commit a940e66f5a on Jun 25, 2021
  33. gades referenced this in commit 63e00005a9 on Jan 30, 2022
  34. DrahtBot locked this on Aug 18, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-16 15:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me