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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
id = 866
title = "linux-user: substantial memory leak when threads are created and destroyed"
state = "closed"
created_at = "2022-02-11T03:11:59.674Z"
closed_at = "2023-02-04T19:12:11.704Z"
labels = ["Closed::Fixed", "linux-user"]
url = "https://gitlab.com/qemu-project/qemu/-/issues/866"
host-os = "Fedora 35 Workstation, Windows 11 21H2 22000.469 WSL2"
host-arch = "x86_64"
qemu-version = "6.1.0-10.fc35, and on master@0a301624c2f4ced3331ffd5bce85b4274fe132af"
guest-os = "QEMU Linux User Mode Emulation"
guest-arch = "ARM"
description = """Substantial memory leak when the following simple program is executed on `qemu-arm`,
```c
// compile with `arm-none-linux-gnueabihf-gcc test_qemu.c -o test_qemu.out -pthread`
#include <assert.h>
#include <pthread.h>
#define MAGIC_RETURN ((void *)42)
void *thread_main(void *arg)
{
return MAGIC_RETURN;
}
int main(int argc, char *argv[])
{
size_t i;
for (i = 0;; i++)
{
pthread_t thread;
assert(pthread_create(&thread, NULL, thread_main, NULL) == 0);
void *ret;
assert(pthread_join(thread, &ret) == 0);
assert(ret == MAGIC_RETURN);
}
return 0;
}
```"""
reproduce = """1.
```
export TOOLCHAIN_PREFIX=arm-none-linux-gnueabihf
export ARMSDK=/${TOOLCHAIN_PREFIX}
export SYSROOT=${ARMSDK}/${TOOLCHAIN_PREFIX}/libc
export CC=${ARMSDK}/bin/${TOOLCHAIN_PREFIX}-gcc
```
2. Download the arm toolchain: `curl --output ${TOOLCHAIN_PREFIX}.tar.xz -L 'https://developer.arm.com/-/media/Files/downloads/gnu-a/10.2-2020.11/binrel/gcc-arm-10.2-2020.11-x86_64-arm-none-linux-gnueabihf.tar.xz?revision=d0b90559-3960-4e4b-9297-7ddbc3e52783&la=en&hash=985078B758BC782BC338DB947347107FBCF8EF6B'`
3. `mkdir -p ${ARMSDK} && tar xf ${TOOLCHAIN_PREFIX}.tar.xz -C ${ARMSDK} --strip-components=1`
4. `$CC test_qemu.c -o test_qemu.out -pthread`
5. `qemu-arm -L $SYSROOT ./test_qemu.out`
6. Observe memory usage keeps ramping up and crashes the process once out of memory."""
additional = """Valgrind annotation logs [annot.log](/uploads/f8d05d8f216d5a589e8da0758a345de6/annot.log) generated by a local build on master@0a301624c2f4ced3331ffd5bce85b4274fe132af from
```bash
valgrind --xtree-memory=full --xtree-memory-file=xtmemory.kcg bin/debug/native/qemu-arm -L $SYSROOT /mnt/f/test_qemu3.out
# Send CTRL-C before the process crashes due to oom
callgrind_annotate --auto=yes --inclusive=yes --sort=curB:100,curBk:100,totB:100,totBk:100,totFdB:100,totFdBk:100 xtmemory.kcg > annot.log
```
#"""
|