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

Fix memory leak #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fix memory leak #32

wants to merge 1 commit into from

Conversation

messmerd
Copy link

@messmerd messmerd commented Sep 3, 2023

In interface.cc, an array of Descriptor objects is dynamically created and then later destroyed by calling delete on pointers to the base class DescriptorStub. However, since DescriptorStub's destructor is non-virtual, the destructors of derived classes are not called and this causes a memory leak which I detected with AddressSanitizer:

==1814137==ERROR: AddressSanitizer: new-delete-type-mismatch on 0x60e0001424a0 in thread T0:
  object passed to delete has wrong type:
  size of the allocated type:   160 bytes;
  size of the deallocated type: 152 bytes.
    #0 0x7f15d641822f in operator delete(void*, unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:172
    #1 0x7f15c5510d3c in caps_so_fini /home/dalton/Documents/lmms_dev2/plugins/LadspaEffect/caps/interface.cc:132
    #2 0x7f15d6d6e24d in _dl_fini elf/dl-fini.c:142
    #3 0x7f15d370a494 in __run_exit_handlers stdlib/exit.c:113
    #4 0x7f15d370a60f in __GI_exit stdlib/exit.c:143
    #5 0x7f15d36eed96 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:74
    #6 0x7f15d36eee3f in __libc_start_main_impl ../csu/libc-start.c:392
    #7 0x55982aedfc34 in _start (/home/dalton/Documents/lmms_dev2/build/lmms+0x798c34)

0x60e0001424a0 is located 0 bytes inside of 160-byte region [0x60e0001424a0,0x60e000142540)
allocated by thread T0 here:
    #0 0x7f15d64171c7 in operator new(unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:99
    #1 0x7f15c55110a4 in caps_so_init /home/dalton/Documents/lmms_dev2/plugins/LadspaEffect/caps/interface.cc:77

SUMMARY: AddressSanitizer: new-delete-type-mismatch ../../../../src/libsanitizer/asan/asan_new_delete.cpp:172 in operator delete(void*, unsigned long)
==1814137==HINT: if you don't care about these errors you may set ASAN_OPTIONS=new_delete_type_mismatch=0
==1814137==ABORTING

This PR fixes the problem by making DescriptorStub's destructor virtual.

@messmerd
Copy link
Author

messmerd commented Sep 3, 2023

It looks like this issue is present upstream, so I just contacted Tim at http://quitte.de/dsp/caps.html#Contact.

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

Successfully merging this pull request may close these issues.

None yet

1 participant