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 Only in VSCode Terminal (C++) #198

Open
patricknaughton01 opened this issue Dec 10, 2024 · 0 comments
Open

Memory Leak Only in VSCode Terminal (C++) #198

patricknaughton01 opened this issue Dec 10, 2024 · 0 comments

Comments

@patricknaughton01
Copy link
Contributor

A memory leak is created when instantiating an empty RobotModel only when running the script in the VSCode terminal, not the default Ubuntu terminal.

Versions:
cmake 3.16.3
gcc 9.4.0
VSCode: 1.95.3
Ubuntu: 20.04

Test code:

#include "Klampt/Modeling/Robot.h"

int main(int argc, char **argv){
    Klampt::RobotModel rm;
    return 0;
}

CMakeLists.txt (assuming Klampt installed at the home directory):

cmake_minimum_required(VERSION 2.6.4)
project(klampt_test)

set(KLAMPT_ROOT "~/Klampt")
set(CMAKE_MODULE_PATH "${KLAMPT_ROOT}/CMakeModules")
FIND_PACKAGE(Klampt REQUIRED)
ADD_DEFINITIONS(${KLAMPT_DEFINITIONS})
INCLUDE_DIRECTORIES(${KLAMPT_INCLUDE_DIRS})

add_executable(test test.cpp)
target_link_libraries(test PUBLIC ${KLAMPT_LIBRARIES})

In VSCode Terminal:

mkdir build
cd build
cmake ..
make
valgrind --leak-check=full --show-leak-kinds=all ./test

yields output:

==223316== Memcheck, a memory error detector
==223316== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==223316== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==223316== Command: ./test
==223316== 
==223316== 
==223316== HEAP SUMMARY:
==223316==     in use at exit: 150 bytes in 3 blocks
==223316==   total heap usage: 3,167 allocs, 3,164 frees, 326,236 bytes allocated
==223316== 
==223316== 8 bytes in 1 blocks are still reachable in loss record 1 of 3
==223316==    at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==223316==    by 0x7E660EC: ??? (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0)
==223316==    by 0x7E7B95A: ??? (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0)
==223316==    by 0x7E64A3C: ??? (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0)
==223316==    by 0x4011B99: call_init.part.0 (dl-init.c:72)
==223316==    by 0x4011CA0: call_init (dl-init.c:30)
==223316==    by 0x4011CA0: _dl_init (dl-init.c:119)
==223316==    by 0x4001139: ??? (in /usr/lib/x86_64-linux-gnu/ld-2.31.so)
==223316== 
==223316== 46 bytes in 1 blocks are definitely lost in loss record 2 of 3
==223316==    at 0x483DFAF: realloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==223316==    by 0x61FF28B: argz_add_sep (argz-addsep.c:35)
==223316==    by 0x618FCD6: newlocale (newlocale.c:112)
==223316==    by 0x80F80DC: ??? (in /usr/lib/x86_64-linux-gnu/libp11-kit.so.0.3.0)
==223316==    by 0x4011B99: call_init.part.0 (dl-init.c:72)
==223316==    by 0x4011CA0: call_init (dl-init.c:30)
==223316==    by 0x4011CA0: _dl_init (dl-init.c:119)
==223316==    by 0x4001139: ??? (in /usr/lib/x86_64-linux-gnu/ld-2.31.so)
==223316== 
==223316== 96 bytes in 1 blocks are still reachable in loss record 3 of 3
==223316==    at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==223316==    by 0x7E66124: ??? (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0)
==223316==    by 0x7E64982: ??? (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0)
==223316==    by 0x7E64A58: ??? (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0)
==223316==    by 0x4011B99: call_init.part.0 (dl-init.c:72)
==223316==    by 0x4011CA0: call_init (dl-init.c:30)
==223316==    by 0x4011CA0: _dl_init (dl-init.c:119)
==223316==    by 0x4001139: ??? (in /usr/lib/x86_64-linux-gnu/ld-2.31.so)
==223316== 
==223316== LEAK SUMMARY:
==223316==    definitely lost: 46 bytes in 1 blocks
==223316==    indirectly lost: 0 bytes in 0 blocks
==223316==      possibly lost: 0 bytes in 0 blocks
==223316==    still reachable: 104 bytes in 2 blocks
==223316==         suppressed: 0 bytes in 0 blocks
==223316== 
==223316== For lists of detected and suppressed errors, rerun with: -s
==223316== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

In ubuntu terminal:

cd ..
rm -rf build
mkdir build
cd build
cmake ..
make
valgrind --leak-check=full --show-leak-kinds=all ./test

yields output

==223579== Memcheck, a memory error detector
==223579== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==223579== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==223579== Command: ./test
==223579== 
==223579== 
==223579== HEAP SUMMARY:
==223579==     in use at exit: 104 bytes in 2 blocks
==223579==   total heap usage: 3,165 allocs, 3,163 frees, 326,160 bytes allocated
==223579== 
==223579== 8 bytes in 1 blocks are still reachable in loss record 1 of 2
==223579==    at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==223579==    by 0x7E660EC: ??? (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0)
==223579==    by 0x7E7B95A: ??? (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0)
==223579==    by 0x7E64A3C: ??? (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0)
==223579==    by 0x4011B99: call_init.part.0 (dl-init.c:72)
==223579==    by 0x4011CA0: call_init (dl-init.c:30)
==223579==    by 0x4011CA0: _dl_init (dl-init.c:119)
==223579==    by 0x4001139: ??? (in /usr/lib/x86_64-linux-gnu/ld-2.31.so)
==223579== 
==223579== 96 bytes in 1 blocks are still reachable in loss record 2 of 2
==223579==    at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==223579==    by 0x7E66124: ??? (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0)
==223579==    by 0x7E64982: ??? (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0)
==223579==    by 0x7E64A58: ??? (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0)
==223579==    by 0x4011B99: call_init.part.0 (dl-init.c:72)
==223579==    by 0x4011CA0: call_init (dl-init.c:30)
==223579==    by 0x4011CA0: _dl_init (dl-init.c:119)
==223579==    by 0x4001139: ??? (in /usr/lib/x86_64-linux-gnu/ld-2.31.so)
==223579== 
==223579== LEAK SUMMARY:
==223579==    definitely lost: 0 bytes in 0 blocks
==223579==    indirectly lost: 0 bytes in 0 blocks
==223579==      possibly lost: 0 bytes in 0 blocks
==223579==    still reachable: 104 bytes in 2 blocks
==223579==         suppressed: 0 bytes in 0 blocks
==223579== 
==223579== For lists of detected and suppressed errors, rerun with: -s
==223579== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

where the 46 bytes are no longer lost.

This seems to be related to the terminal in which the executable is run, not where it was built. Running the executable built by the ubuntu terminal in the VSCode terminal generates a leak, while the reverse does not.

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