File: test_pthread_lsan_leak.cpp

package info (click to toggle)
emscripten 3.1.69%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 121,872 kB
  • sloc: ansic: 636,110; cpp: 425,974; javascript: 78,401; python: 58,404; sh: 49,154; pascal: 5,237; makefile: 3,365; asm: 2,415; lisp: 1,869
file content (42 lines) | stat: -rw-r--r-- 798 bytes parent folder | download | duplicates (3)
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 <stdlib.h>
#include <string.h>
#include <thread>
#include <emscripten.h>
#include <sanitizer/lsan_interface.h>

void *global_ptr;
thread_local void *tls_ptr;
std::atomic<bool> thread_done;

void f(void) {
  void *local_ptr = malloc(42);
  memset(local_ptr, 0, 42);
}

void g(void) {
  void *stuff = malloc(3432);
  stuff = 0;
  tls_ptr = malloc(1234);
  tls_ptr = 0;
  atomic_store(&thread_done, true);
  while (1);
}

int main(int argc, char **argv) {
  std::thread t(g);
  t.detach();

  global_ptr = malloc(1337);
  tls_ptr = malloc(420);
  tls_ptr = 0;
  memset(global_ptr, 0, 42);
  global_ptr = 0;
  f();
  memset(calloc(16, 128), 48, 2048);
  while (!atomic_load(&thread_done));

  __lsan_do_leak_check();
  fprintf(stderr, "LSAN TEST COMPLETE\n");
  return 0;
}