commial / ttd-bindings

Bindings for Microsoft WinDBG TTD
211 stars 31 forks source link

Memory leak in example_tenet #26

Open synacktiv-rj opened 1 year ago

synacktiv-rj commented 1 year ago

Hello,

A memory leak occurs in the loop used to call ttdcursor.ReplayForward, since the caller of Cursor::GetCrossPlatformContext must free the context, and this is never done.

Here, the previous context containing the allocation is overriden without beeing freeed:

https://github.com/commial/ttd-bindings/blob/fb836bdb738bf9170e73349994113c8a92f0feb8/example_tenet/main.cpp#L243

My quick fix to deal with this issue was:

if (old_context)
    free(old_context);

I think the context should also be freed when this condition is true:

https://github.com/commial/ttd-bindings/blob/fb836bdb738bf9170e73349994113c8a92f0feb8/example_tenet/main.cpp#L239-L240

Rémi

mrexodia commented 1 year ago

I changed the way the context is allocated in my fork. Still waiting for my other two PRs to be merged though…

commial commented 1 year ago

Hi there,

@synacktiv-rj: you're obviously right, and I can easily reproduce it when running the example_tenet exe on a ~300MB trace.

@mrexodia : I've indeed been away from this repo for a few month, but I've since merged your cmake PR (thanks, again). If you still want to contribute to this repo, I would be happy to merge your context allocation changes.

mrexodia commented 1 year ago

Alright, I’ll try to upstream them. Locally I started a full rewrite, but obviously life got in the way and it didn’t get very far 😅