brainboxdotcc / DPP

C++ Discord API Bot Library - D++ is Lightweight and scalable for small and huge bots!
https://dpp.dev/
Apache License 2.0
1.07k stars 163 forks source link

fix: avoid memory leaks in event_map #1043

Closed rept1d closed 10 months ago

rept1d commented 10 months ago

This PR fixes memory leaks detected by Valgrind which occur because events allocated in initialization of eventmap are never deallocated.

These leaks are harmless because these objects are currently supposed to live for the whole duration of the program, but it's still good to not have these leaks at all. I fix them by making the pointers stored in eventmap (renamed to event_map for better readability) point to events with static storage duration. This way we also avoid unnecessary memory allocations.

I should note that it seems a bit weird to me that these event objects live that long in the first place. They have no reason for that other than making the implementation simpler. It might be worth looking for a cleaner a solution in a separate PR.

Code change checklist

netlify[bot] commented 10 months ago

Deploy Preview for dpp-dev ready!

Name Link
Latest commit 536a49f282304207b704828bb07efcb3745a99ef
Latest deploy log https://app.netlify.com/sites/dpp-dev/deploys/658150ab8f0c1d0008420d2e
Deploy Preview https://deploy-preview-1043--dpp-dev.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

CLAassistant commented 10 months ago

CLA assistant check
All committers have signed the CLA.

Jaskowicz1 commented 10 months ago

Congrats on your first PR! I know you said you've tested this, but have you ran a unit test with this and made sure there's no errors there?

braindigitalis commented 10 months ago

pretty sure there's already a type called event_map (a container of guild events) but apart from that looks good

rept1d commented 10 months ago

pretty sure there's already a type called event_map (a container of guild events) but apart from that looks good

I don't think there is, there are only scheduled_event_map and event_member_map.