File: tst-leaks1.c

package info (click to toggle)
glibc 2.28-10
  • links: PTS, VCS
  • area: main
  • in suites: buster, buster-backports
  • size: 272,168 kB
  • sloc: ansic: 1,008,602; asm: 259,607; makefile: 11,271; sh: 10,477; python: 6,910; cpp: 4,992; perl: 2,258; awk: 2,005; yacc: 290; pascal: 182; sed: 73
file content (42 lines) | stat: -rw-r--r-- 896 bytes parent folder | download | duplicates (25)
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 inintialization 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>