Lifetime issue in ReleaseWallet(CWallet* wallet) #16668

issue practicalswift opened this issue on August 20, 2019
  1. practicalswift commented at 10:39 AM on August 20, 2019: contributor

    While checking #16661 I stumbled upon what seems to be a lifetime issue in ReleaseWallet(CWallet* wallet) (wallet.cpp).

    https://github.com/bitcoin/bitcoin/blob/fa6431055abfacea4f72ef11d061c7c755de327a/src/wallet/wallet.cpp#L107-L111

    After delete wallet; the pointer is invalid and shouldn't be used like in the call g_unloading_wallet_set.erase(wallet).

    The code was introduced in #14941 which was merged into master on January 15, 2019.

    In addition to fixing this specific instance it might be worth thinking about how we can use static analysis to automatically catch this class of issues going forward :-)

  2. fanquake added the label Wallet on Aug 20, 2019
  3. promag commented at 10:45 AM on August 20, 2019: member

    It's not dereferenced so it should be fine?

  4. practicalswift commented at 10:48 AM on August 20, 2019: contributor

    @promag Isn't any use of a pointer that has been invalidated due to deallocation prohibited?

  5. practicalswift commented at 11:07 AM on August 20, 2019: contributor

    @promag From the C++11 standard:

    If the argument given to a deallocation function in the standard library is a pointer that is not the null pointer value (4.10), the deallocation function shall deallocate the storage referenced by the pointer, rendering invalid all pointers referring to any part of the deallocated storage.

    The effect of using an invalid pointer value (including passing it to a deallocation function) is undefined.

    On some implementations, it causes a system-generated runtime fault.

  6. promag commented at 11:23 AM on August 20, 2019: member

    Ok, it's easily fixed by grabbing the set iterator before deleting.

  7. practicalswift commented at 1:00 PM on August 20, 2019: contributor

    @promag Would you mind fixing it since this is your code originally? Let me know otherwise and I'll jump in of course :-)

  8. promag commented at 1:38 PM on August 20, 2019: member

    Sure will do

  9. MarcoFalke added the label good first issue on Aug 22, 2019
  10. ryanofsky commented at 4:56 PM on August 26, 2019: member
  11. fanquake closed this on Aug 31, 2019

  12. sidhujag referenced this in commit 1914c7850e on Aug 31, 2019
  13. deadalnix referenced this in commit a4149bf01f on Jan 30, 2020
  14. jonspock referenced this in commit 0851355107 on Feb 29, 2020
  15. jonspock referenced this in commit 7e42d1dba9 on Mar 2, 2020
  16. jonspock referenced this in commit 14f6d2d8e8 on Mar 7, 2020
  17. jonspock referenced this in commit 8e9f58daac on Mar 14, 2020
  18. jonspock referenced this in commit 30cb06b9e6 on Mar 21, 2020
  19. jonspock referenced this in commit 6e13cfc7d9 on Mar 24, 2020
  20. jonspock referenced this in commit 9f9f710cd2 on Apr 6, 2020
  21. jonspock referenced this in commit 0b53281407 on Apr 8, 2020
  22. jonspock referenced this in commit d1b13bdb29 on Apr 8, 2020
  23. jonspock referenced this in commit 0078d4f3c9 on Apr 8, 2020
  24. jonspock referenced this in commit 3d7afb7d3b on Apr 8, 2020
  25. jonspock referenced this in commit cc02488253 on Apr 9, 2020
  26. jonspock referenced this in commit b280b45879 on Apr 17, 2020
  27. jonspock referenced this in commit 2ae9847a09 on May 23, 2020
  28. jonspock referenced this in commit f5f5e1a62e on May 25, 2020
  29. jonspock referenced this in commit 3f2f4f3ced on Jul 9, 2020
  30. jonspock referenced this in commit 296ed5821c on Jul 10, 2020
  31. jonspock referenced this in commit a40833e552 on Jul 17, 2020
  32. jonspock referenced this in commit 4ab4888f02 on Jul 17, 2020
  33. jonspock referenced this in commit 45a6d55cb3 on Jul 20, 2020
  34. jonspock referenced this in commit 51b976e1e3 on Jul 29, 2020
  35. jonspock referenced this in commit fc4c824e55 on Jul 31, 2020
  36. jonspock referenced this in commit 48dd61cfb9 on Aug 5, 2020
  37. jonspock referenced this in commit cb6f295dce on Aug 6, 2020
  38. jonspock referenced this in commit 4030095600 on Aug 7, 2020
  39. proteanx referenced this in commit 8b0c4f6c7f on Aug 8, 2020
  40. PastaPastaPasta referenced this in commit 2be6319ca1 on Sep 11, 2021
  41. PastaPastaPasta referenced this in commit 3188d9af98 on Sep 11, 2021
  42. PastaPastaPasta referenced this in commit 6f9cb7a8e8 on Sep 12, 2021
  43. PastaPastaPasta referenced this in commit 5145ef9b9e on Sep 12, 2021
  44. PastaPastaPasta referenced this in commit 2bbde0320e on Sep 12, 2021
  45. PastaPastaPasta referenced this in commit 5484e05400 on Sep 14, 2021
  46. PastaPastaPasta referenced this in commit 44c7bb618e on Sep 14, 2021
  47. DrahtBot locked this on Dec 16, 2021

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-14 18:14 UTC

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