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 a leaked cairo context in render_to_surface() in waveform.c #75

Merged
merged 1 commit into from May 1, 2021

Conversation

musicinmybrain
Copy link
Contributor

On Fedora 34 x86_64, the valgrind checks in tests/test_wrapper give:

valgrind bin/sndfile-generate-chirp   : ok
valgrind bin/sndfile-resample         : 1 errors, 0 bytes leaked
valgrind bin/sndfile-resample         : 1 errors, 0 bytes leaked
valgrind bin/sndfile-resample         : 1 errors, 0 bytes leaked
valgrind bin/sndfile-spectrogram      : 0 errors, 256 bytes leaked
valgrind bin/sndfile-waveform         : 0 errors, 392 bytes leaked

This PR adds a missing call to cairo_destroy() in render_to_surface() in waveform.c to fix the leak in sndfile-waveform:

==189578== Memcheck, a memory error detector
==189578== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==189578== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
==189578== Command: bin/sndfile-waveform tmp-20210430T125133/chirp.wav tmp-20210430T125133/wavform.png
==189578==
==189578==
==189578== HEAP SUMMARY:
==189578==     in use at exit: 675,260 bytes in 25 blocks
==189578==   total heap usage: 3,412 allocs, 3,387 frees, 16,867,748 bytes allocated
==189578==
==189578== 642,256 (392 direct, 641,864 indirect) bytes in 1 blocks are definitely lost in loss record 25 of 25
==189578==    at 0x484086F: malloc (vg_replace_malloc.c:380)
==189578==    by 0x49260E4: ??? (in /usr/lib64/libcairo.so.2.11704.0)
==189578==    by 0x4926785: cairo_image_surface_create (in /usr/lib64/libcairo.so.2.11704.0)
==189578==    by 0x10AD06: UnknownInlinedFun (waveform.c:925)
==189578==    by 0x10AD06: UnknownInlinedFun (waveform.c:1000)
==189578==    by 0x10AD06: main (waveform.c:1281)
==189578==
==189578== LEAK SUMMARY:
==189578==    definitely lost: 392 bytes in 1 blocks
==189578==    indirectly lost: 641,864 bytes in 4 blocks
==189578==      possibly lost: 0 bytes in 0 blocks
==189578==    still reachable: 33,004 bytes in 20 blocks
==189578==         suppressed: 0 bytes in 0 blocks
==189578== Reachable blocks (those to which a pointer was found) are not shown.
==189578== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==189578==
==189578== For lists of detected and suppressed errors, rerun with: -s
==189578== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

The result is:

valgrind bin/sndfile-generate-chirp   : ok
valgrind bin/sndfile-resample         : 1 errors, 0 bytes leaked
valgrind bin/sndfile-resample         : 1 errors, 0 bytes leaked
valgrind bin/sndfile-resample         : 1 errors, 0 bytes leaked
valgrind bin/sndfile-spectrogram      : 0 errors, 256 bytes leaked
valgrind bin/sndfile-waveform         : ok

See also #74, which fixes the problems with sndfile-resample.

@evpobr
Copy link
Member

evpobr commented May 1, 2021

Hi @musicinmybrain, thanks for pull request!

@evpobr evpobr requested review from SoapGentoo and evpobr May 1, 2021 12:44
@evpobr evpobr added this to the v1.5.1 milestone May 1, 2021
@evpobr evpobr merged commit fb74006 into libsndfile:master May 1, 2021
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

3 participants