about summary refs log tree commit diff
path: root/elf/tst-leaks1.c
blob: e9038fc932e018296d01c447568246d21f42e3c0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <dlfcn.h>
#include <mcheck.h>
#include <stdlib.h>

static int
do_test (void)
{
  void *h;
  int ret = 0;
  /* Carry out *one* failing call to dlopen before starting mtrace to
     force any one-time initialization that may happen to the
     executable link map e.g. expansion and caching of $ORIGIN.  */
  h = dlopen ("$ORIGIN/tst-leaks1.o", RTLD_LAZY);
  if (h != NULL)
    {
      puts ("dlopen unexpectedly succeeded");
      ret = 1;
      dlclose (h);
    }

  /* Start tracing and run each test 5 times to see if there are any
     leaks in the failing dlopen.  */
  mtrace ();

  for (int i = 0; i < 10; i++)
    {
      h = dlopen (i < 5
		  ? "./tst-leaks1.c"
		  : "$ORIGIN/tst-leaks1.o", RTLD_LAZY);
      if (h != NULL)
	{
	  puts ("dlopen unexpectedly succeeded");
	  ret = 1;
	  dlclose (h);
	}
    }

  return ret;
}

#include <support/test-driver.c>