Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak in PPC target #1680

Closed
relapids opened this issue Aug 15, 2022 · 0 comments
Closed

Memory leak in PPC target #1680

relapids opened this issue Aug 15, 2022 · 0 comments

Comments

@relapids
Copy link
Contributor

Steps to reproduce: Build with LeakSanitizer (enabled by default with AddressSanitizer on Linux) and run the tests/samples.

Example build steps:

$ cmake -S ../repo/ -B . -G Ninja -D CMAKE_C_COMPILER=clang -D CMAKE_C_FLAGS=-fsanitize=address -D CMAKE_BUILD_TYPE=Debug
$ cmake --build .

Test output for test_ppc32_add:

Test test_ppc32_add...                          [ OK ]

=================================================================
==7079==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 3072 byte(s) in 1 object(s) allocated from:
    #0 0x557cedfbc3e1 in __interceptor_calloc (/home/builder/unicorn/build/test_ppc+0xdb3e1)
    #1 0x7f1c603e0ec4 in g_malloc0 /home/builder/unicorn/repo/glib_compat/gmem.c:139:15
    #2 0x7f1c603e0f74 in g_malloc0_n /home/builder/unicorn/repo/glib_compat/gmem.c:168:12
    #3 0x7f1c627465bc in init_ppc_proc /home/builder/unicorn/repo/qemu/target/ppc/translate_init.inc.c:9258:29
    #4 0x7f1c62720887 in ppc_cpu_realize /home/builder/unicorn/repo/qemu/target/ppc/translate_init.inc.c:9922:5
    #5 0x7f1c6271fc02 in cpu_ppc_init_ppc /home/builder/unicorn/repo/qemu/target/ppc/translate_init.inc.c:11191:5
    #6 0x7f1c62522278 in ppc_cpus_init /home/builder/unicorn/repo/qemu/target/ppc/unicorn.c:403:11
    #7 0x7f1c603d3b73 in machine_initialize /home/builder/unicorn/repo/qemu/softmmu/vl.c:56:12
    #8 0x7f1c603c48c0 in uc_init /home/builder/unicorn/repo/uc.c:228:9
    #9 0x7f1c603c8c4e in uc_mem_map /home/builder/unicorn/repo/uc.c:1042:5
    #10 0x557cee00750c in uc_common_setup /home/builder/unicorn/repo/tests/unit/test_ppc.c:10:5
    #11 0x557cee0049e7 in test_ppc32_add /home/builder/unicorn/repo/tests/unit/test_ppc.c:20:5
    #12 0x557cee006f16 in acutest_do_run_ /home/builder/unicorn/repo/tests/unit/acutest.h:1026:9
    #13 0x557cee004253 in acutest_run_ /home/builder/unicorn/repo/tests/unit/acutest.h:1124:23
    #14 0x557cee00184e in main /home/builder/unicorn/repo/tests/unit/acutest.h:1831:13
    #15 0x7f1c5f9552cf  (/usr/lib/libc.so.6+0x232cf) (BuildId: e637217a46491314667a7a37b2155cb07afc1a40)

SUMMARY: AddressSanitizer: 3072 byte(s) leaked in 1 allocation(s).

It looks like the following allocation(s) in qemu\target\ppc\translate_init.inc.c is not handled in qemu\target\ppc\unicorn.c (ppc_release):

    /* Allocate TLBs buffer when needed */
    if (env->nb_tlb != 0) {
        int nb_tlb = env->nb_tlb;
        if (env->id_tlbs != 0) {
            nb_tlb *= 2;
        }
        switch (env->tlb_type) {
        case TLB_6XX:
            env->tlb.tlb6 = g_new0(ppc6xx_tlb_t, nb_tlb);
            break;
        case TLB_EMB:
            env->tlb.tlbe = g_new0(ppcemb_tlb_t, nb_tlb);
            break;
        case TLB_MAS:
            env->tlb.tlbm = g_new0(ppcmas_tlb_t, nb_tlb);
            break;
        }
        /* Pre-compute some useful values */
        env->tlb_per_way = env->nb_tlb / env->nb_ways;
    }
wtdcode added a commit that referenced this issue Aug 16, 2022
Fix memory leak in PPC target. (#1680)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant