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

LeakSanitizer: detected memory leaks when using -float argument with exr_ctl_exr #135

Closed
michaeldsmith opened this issue Aug 13, 2023 · 2 comments · Fixed by #136
Closed

Comments

@michaeldsmith
Copy link
Collaborator

Running exr_ctl_exr without -float argument results in no leaks


217: Test command: /home/runner/work/CTL/CTL/build/OpenEXR_CTL/exr_ctl_exr/exr_ctl_exr "-C" "change_saturation" "/home/runner/work/CTL/CTL/unittest/exr_ctl_exr/marci-512.exr" "/home/runner/work/CTL/CTL/build/unittest/exr_ctl_exr/output/exr-ctl-exr-noargs.exr"
217: Working Directory: /home/runner/work/CTL/CTL/build/OpenEXR_CTL/exr_ctl_exr
217: Test timeout computed to be: 10000000
217/224 Test #217: exr-ctl-exr-noargs ................................................   Passed    0.22 sec

Running exr_ctl_exr with -float argument results in leak

220: Test command: /home/runner/work/CTL/CTL/build/OpenEXR_CTL/exr_ctl_exr/exr_ctl_exr "-C" "change_saturation" "-float" "sScale" "1.0" "/home/runner/work/CTL/CTL/unittest/exr_ctl_exr/marci-512.exr" "/home/runner/work/CTL/CTL/build/unittest/exr_ctl_exr/output/exr-ctl-exr-sScale-1.0.exr"
220: Working Directory: /home/runner/work/CTL/CTL/build/OpenEXR_CTL/exr_ctl_exr
220: Test timeout computed to be: 10000000
220: 
220: =================================================================
220: ==5715==ERROR: LeakSanitizer: detected memory leaks
220: 
220: Direct leak of 16 byte(s) in 1 object(s) allocated from:
220:     #0 0x7fa0a94881e7 in operator new(unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:99
220:     #1 0x55d4daeed287 in getNameAndFloat /home/runner/work/CTL/CTL/OpenEXR_CTL/exr_ctl_exr/main.cpp:167
220:     #2 0x55d4daeed287 in main /home/runner/work/CTL/CTL/OpenEXR_CTL/exr_ctl_exr/main.cpp:252
220:     #3 0x7fa0a8ac1d8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f)
220: 
220: SUMMARY: AddressSanitizer: 16 byte(s) leaked in 1 allocation(s).
220/224 Test #220: exr-ctl-exr-sScale-1.0 ............................................***Failed    0.65 sec
@michaeldsmith
Copy link
Collaborator Author

leak details from valgrind:

+ valgrind -s --error-exitcode=1 --leak-check=full --track-origins=yes --show-leak-kinds=all ../../OpenEXR_CTL/exr_ctl_exr/exr_ctl_exr -C change_saturation -float sScale 1.2 ../../../unittest/exr_ctl_exr/marci-512.exr ./output/exr_ctl_exr-sScale-1.2.exr
==5919== Memcheck, a memory error detector
==5919== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==5919== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==5919== Command: ../../OpenEXR_CTL/exr_ctl_exr/exr_ctl_exr -C change_saturation -float sScale 1.2 ../../../unittest/exr_ctl_exr/marci-512.exr ./output/exr_ctl_exr-sScale-1.2.exr
==5919== 
==5919== 
==5919== HEAP SUMMARY:
==5919==     in use at exit: 16 bytes in 1 blocks
Failure: valgrind detected errors
==5919==   total heap usage: 8,223 allocs, 8,222 frees, 54,285,903 bytes allocated
==5919== 
==5919== 16 bytes in 1 blocks are definitely lost in loss record 1 of 1
==5919==    at 0x4849013: operator new(unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==5919==    by 0x1222A5: (anonymous namespace)::getNameAndFloat(int, char**, int&, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, Imf_2_5::Attribute*, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, Imf_2_5::Attribute*> > >&) (main.cpp:167)
==5919==    by 0x12296C: main (main.cpp:252)
==5919== 
==5919== LEAK SUMMARY:
==5919==    definitely lost: 16 bytes in 1 blocks
==5919==    indirectly lost: 0 bytes in 0 blocks
==5919==      possibly lost: 0 bytes in 0 blocks
==5919==    still reachable: 0 bytes in 0 blocks
==5919==         suppressed: 0 bytes in 0 blocks
==5919== 
==5919== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

@michaeldsmith
Copy link
Collaborator Author

this leak can be fixed by deleting the dynamically allocated map objects contained in extraAttrs before exiting, by adding the following code at line 354 of /OpenEXR_CTL/exr_ctl_exr/main.cpp


// clean up dynamically allocated memory
if(extraAttrs.size() > 0)
{
  for(AttrMap::iterator it=extraAttrs.begin() ; it!=extraAttrs.end() ; it++)
  {
    delete it->second;
  }
}
extraAttrs.clear();

michaeldsmith added a commit to michaeldsmith/CTL that referenced this issue Aug 14, 2023
michaeldsmith added a commit that referenced this issue Aug 14, 2023
* add exr_ctl_exr unit tests, closes #129 

* add valgrind tests for exr_ctl_exr

* free memory used by extraAttrs, closes #135
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 a pull request may close this issue.

1 participant