r/cpp • • Jun 01 '22

Post-mortem of a long-standing bug in video Game Path Of Exile, which was caused by a stale pointer

https://www.pathofexile.com/forum/view-thread/3277814
202 Upvotes

91 comments sorted by

View all comments

52

u/mark_99 Jun 01 '22

TL;DR if your code uses raw, non-owning, non-refcounted pointers to resources which can be dynamically deallocated / unloaded then it's an accident waiting to happen (to be fair this seems to have been largely due to a library they were using).

And/or use a heap checker / sanitizer once in a while.

4

u/matthieum Jun 02 '22

And/or use a heap checker / sanitizer once in a while.

I don't think that's the issue.

The address is only ever used as a key to the map, it's not dereferenced, as far as I understand, and thus I doubt any heap checker / sanitizer would catch the issue there.

I do think the code is UB still, as in I do not think it is legal to compare the stale pointer to any other, but I am not aware of any sanitizer catching such issues.

3

u/irqlnotdispatchlevel Jun 02 '22

I do think the code is UB still, as in I do not think it is legal to compare the stale pointer to any other, but I am not aware of any sanitizer catching such issues.

I'd be curious what someone with more knowledge about the C++ standard would say about this. Doing a bit of googling, I arrived at this SO question and it seems like this is implementation defined?

1

u/matthieum Jun 03 '22

Oh interesting. I always thought it was outright UB, I may have mixed it up with the behavior of realloc.

Then again, implementation defined and unspecified in the implementation (as seems to be the case with GCC) is not far off...