Fix memory leaks in qt/guiutil.cpp #11156

pull danra wants to merge 1 commits into bitcoin:master from danra:fix/qt-guiutil-memory-leaks changing 1 files +30 −11
  1. danra commented at 10:29 AM on August 26, 2017: contributor

    on macOS: listSnapshot was leaking in findStartupItemInList() bitcoinAppUrl was leaking in [Get|Set]StartOnSystemStartup()

  2. Fix memory leaks in qt/guiutil.cpp
    on macOS:
    listSnapshot was leaking in findStartupItemInList()
    bitcoinAppUrl was leaking in [Get|Set]StartOnSystemStartup()
    9b348ff9eb
  3. laanwj added the label GUI on Aug 26, 2017
  4. laanwj added the label MacOSX on Aug 26, 2017
  5. promag commented at 11:22 AM on August 28, 2017: member

    CFArrayGetCount dereferences listSnapshot and if it's nullptr then it crashes, so how have you tested this?

  6. danra commented at 8:26 PM on August 28, 2017: contributor

    @promag Not sure I understand the question, do you mean

    +    if (listSnapshot == nullptr) {
    +        return nullptr;
    +    }
    

    added at 784-786?

    This is just for safety, it's not really expected for listSnapshot to be nullptr. I think it makes sense to add this safety in the context of not doing CFRelease on nullptr at the end. You're right that even without the added lines above, in case of listSnapshot == nullptr there will probably be a crash even before we get to the CFRelease. Still, seems cleaner to me.

    Also, in the unlikely case that listSnapshot is set to nullptr, we will return nullptr instead of crashing, which is probably nicer behavior anyway. (though, it's up to the caller whether it itself would crash or not)

  7. ryanofsky commented at 6:17 PM on August 29, 2017: member

    utACK 9b348ff9eb75e04249dfa873a34e0d1a31993b9c. Seems right, though maybe it would be simpler with an RAII helper class:

    struct CFReleaser
    {
        CFReleaser(CFTypeRef cf) m_cf(cf) {}
        ~CFReleaser() { if (m_cf) CFRelease(m_cf); }
        CFTypeRef m_cf;
    };
    
  8. danra commented at 7:39 AM on August 30, 2017: contributor

    @ryanofsky I agree, just didn't want to do two things at once - introduce such a class as well as fix problematic code. Once this is merged I'm for doing a separate pull requests with a commit that introduces such a class, followed by commits which make use of it.

  9. jonasschnelli commented at 4:35 PM on September 3, 2017: contributor

    utACK 9b348ff9eb75e04249dfa873a34e0d1a31993b9c. I think we should also get rid of the OSX Growl support.

  10. laanwj commented at 10:18 PM on September 5, 2017: member

    I really like the idea of using a RAII class here. Much easier to check whether all possible exit paths are covered, and exception-safety comes for free.

  11. jonasschnelli commented at 5:01 PM on September 7, 2017: contributor

    I agree an RAII approach would be much better. But until someone comes up with an RAII for that pure OSX stuff, I think this is an valid improvement.

    Tested ACK 9b348ff9eb75e04249dfa873a34e0d1a31993b9c. Could not find any leaks with macOS instruments (leak detector) during notifications.

  12. jonasschnelli merged this on Sep 7, 2017
  13. jonasschnelli closed this on Sep 7, 2017

  14. jonasschnelli referenced this in commit a3624ddb1a on Sep 7, 2017
  15. PastaPastaPasta referenced this in commit 8836221f78 on Sep 23, 2019
  16. PastaPastaPasta referenced this in commit 7eeaa67b4c on Sep 24, 2019
  17. PastaPastaPasta referenced this in commit 028a2542d1 on Nov 19, 2019
  18. PastaPastaPasta referenced this in commit 7377fc8c14 on Nov 21, 2019
  19. PastaPastaPasta referenced this in commit 3e9d53d987 on Dec 9, 2019
  20. PastaPastaPasta referenced this in commit b1a7734306 on Jan 1, 2020
  21. PastaPastaPasta referenced this in commit c0a501a8ce on Jan 2, 2020
  22. PastaPastaPasta referenced this in commit 633acc1c7c on Jan 2, 2020
  23. PastaPastaPasta referenced this in commit 40c9708fe6 on Jan 2, 2020
  24. PastaPastaPasta referenced this in commit ce464a97ce on Jan 2, 2020
  25. PastaPastaPasta referenced this in commit 6c420e87ac on Jan 2, 2020
  26. PastaPastaPasta referenced this in commit 9044d5315b on Jan 3, 2020
  27. ckti referenced this in commit c58b1a695e on Mar 28, 2021
  28. furszy referenced this in commit 4a6d1000ed on May 11, 2021
  29. DrahtBot locked this on Sep 8, 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-21 18:15 UTC

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