[PATCH] D31295: Add free_on_realloc_zero=true flag for compatibility with allocators which allow a realloc(p, 0) and don't free the pointer.

Aleksey Shlyapnikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 24 13:56:09 PDT 2017

alekseyshl accepted this revision.
alekseyshl added inline comments.
This revision is now accepted and ready to land.

Comment at: test/asan/TestCases/realloc.cc:11
+int main(int argc, char **argv) {
+  void *p = malloc(argc);
+  p = realloc(p, 0);
filcab wrote:
> alekseyshl wrote:
> > Why argc and not the particular number of bytes?
> It was originally to try to avoid clang optimizing away the memory allocations. Which doesn't make sense since I'm passing `-O0`. Doesn't hurt, though. Let me know if you'd rather have a constant anyway.
Yes, please.

__asm__ __volatile__("" : : "r"(p) : "memory"); after malloc should prevent optimizations.


More information about the llvm-commits mailing list