5 ms·
A long time ago I found some memory problems in a C++ codebase we had inherited and that crashes from time. In Windows you can protect memory blocks with a func
by maxxxxx 9y ago
A long time ago I found some memory problems in a C++ codebase we had inherited and that crashes from time. In Windows you can protect memory blocks with a function call so I overloaded new and malloc and added some protected blocks before and after the actual memory. Then we ran the code for a lot and it would fault right at the point of the memory overwrite instead of some place later. It made the code very slow but we found problems that were incredibly hard to find in any other way.
- dkersten 9y agoI had similar memory issues once and was able to trace it using valgrind, which afaik did something similar under the hood.
- jclulow 9y agoOn illumos you can use libumem to replace malloc() via LD_PRELOAD, and then you can instruct it to do the same thing via the UMEM_DEBUG environment variable. It's a fantastic technique for catching these issues without completely destroying application performance. See also: https://illumos.org/man/umem_debug https://illumos.org/man/umem_debug
- xcudfg89du8fg90 9y agoBest BOFH comment this week! Instead of suggesting modern tooling such as address sanitizer, poster suggest switching development to obscure unix os. Poster profile even lists them working with loads of operating systems, this one included. And still they debug memory errors like it's 1963. Priceless!
- jjnoakes 9y agoThese days the gcc and clang memory/address sanitizers can do this quite nicely, and they tend to have low overhead as well (in my limited experience so far).
- sebcat 9y agoASan has lower overhead than Valgrind, and is great when you cross-compile something to an embedded/constrained system. I have however observed noticeable overhead on code doing many small allocations. Which was nice to be able to observe, because the code didn't need to do many small allocations.
- xxpor 9y agoWhen running a test suite at work with ASan + UBsan turned on, the test goes from taking ~30 seconds to ~20 minutes. So there's certainly some pathological cases.
- martincmartin 9y agoTry it with just ASan. Some of the UBsan checks can be quite expensive. Also, check how much free ram your computer has when running with ASan. It may be running out of RAM, and e.g. spending a lot of time looking for other memory to free, or even swapping.
- zwieback 9y agoWe did the same thing for some device driver code and also use a tool called "Boundschecker", back in the 90s. I just checked and it still exists!
- maxxxxx 9y agoWe also had BoundsChecker but it was my little library that found most bugs eventually :)
- deleted 9y ago[deleted]
- cpeterso 9y agoThe Windows system heaps include a similar feature called PageHeap. You can enabled it for any process using Microsoft's pageheap.exe utility. It uses a lot of extra (virtual) memory and doesn't work well for applications that have their own memory sub-allocator like jemalloc or dlmalloc. https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/gflags-and-pageheap https://docs.microsoft.com/en-us/windows-hardware/drivers/de...
- kazinator 9y agoThis approach was implemented in Bruce Perens' "Electric Fence" library [1987]. https://en.wikipedia.org/wiki/Electric_Fence https://en.wikipedia.org/wiki/Electric_Fence I think he might have developed that while at Pixar.
- deleted 9y ago[deleted]