Home | History | Annotate | Download | only in tests
      1 /* For a long time (from Valgrind 1.0 to 1.9.6, AFAICT) when realloc() was
      2    called and made a block smaller, or didn't change its size, the
      3    ExeContext of the block was not updated;  therefore any errors that
      4    referred to it would state that it was allocated not by the realloc(),
      5    but by the previous malloc() or whatever.  While this is true in one
      6    sense, it is misleading and not what you'd expect.  This test
      7    demonstrates this -- 'x' and 'y' are unchanged and shrunk, and their
      8    ExeContexts should be updated upon their realloc().  I hope that's clear.
      9 */
     10 #include <stdlib.h>
     11 
     12 int main(void)
     13 {
     14    int* x = malloc(5);
     15    int* y = malloc(10);
     16    int* z = malloc(2);
     17    int a, b, c;
     18 
     19    x = realloc(x, 5);   // same size
     20    y = realloc(y, 5);   // make smaller
     21    z = realloc(z, 5);   // make bigger
     22 
     23    a = (x[5] == 0xdeadbeef ? 1 : 0);
     24    b = (y[5] == 0xdeadbeef ? 1 : 0);
     25    c = (z[5] == 0xdeadbeef ? 1 : 0);
     26 
     27    return a + b + c;
     28 }
     29