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

[PATCH] Fix memory leaks, null pointer dereference #102

Closed
SDLBugzilla opened this issue Feb 11, 2021 · 0 comments
Closed

[PATCH] Fix memory leaks, null pointer dereference #102

SDLBugzilla opened this issue Feb 11, 2021 · 0 comments

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: 1.2.11
Reported for operating system, platform: All, All

Comments on the original bug report:

On 2011-08-07 00:27:36 +0000, Joshua Beck wrote:

Created attachment 670
Patch that fixes some memory errors against current hg

cppcheck found these errors:

[load_flac.c:337]: (error) Memory leak: client_data
[music_cmd.c:177]: (error) Possible null pointer dereference: argv - otherwise it is redundant to check if argv is null at line 172
[mixer.c:1294]: (error) Memory leak: new_e
[mixer.c:654]: (error) Memory leak: wavecvt.buf
[playmus.c:73]: (error) fflush() called on input stream "stdin" may result in undefined behaviour
[playwave.c]: (information) Interrupted checking because of too many #ifdef configurations.
[music.c]: (information) Interrupted checking because of too many #ifdef configurations.
[timidity/readmidi.c:115]: (error) Dereferencing 's' after it is deallocated / released

I fixed the ones in mixer.c and timidity/readmidi.c. The others I didn't know if they were false positives or not.

On 2011-08-24 23:21:45 +0000, Ryan C. Gordon wrote:

This is now hg changeset 563dbb082a17, thanks!

--ryan.

On 2011-09-10 23:05:35 +0000, Lee wrote:

With this patch (in particular the change to mixer.c:654) I'm getting a segfault sometimes and when calling Mix_FreeChunk a crash in 'free'.

This is because wavecvt.buf is actually assigned to chunk->abuf and is supposed to be freed when Mix_FreeChunk is called. So when something tries to play the audio it accesses the freed memory (which can cause a segfault or random sounds), and when Mix_FreeChunk tries to free chunk->abuf it was already freed in Mix_LoadWav.

On 2011-09-14 09:24:09 +0000, Ryan C. Gordon wrote:

(In reply to comment # 2)

This is because wavecvt.buf is actually assigned to chunk->abuf and is supposed
to be freed when Mix_FreeChunk is called. So when something tries to play the
audio it accesses the freed memory (which can cause a segfault or random
sounds), and when Mix_FreeChunk tries to free chunk->abuf it was already freed
in Mix_LoadWav.

Whoops, you're right. I've fixed this in hg changeset 675a11e697c6.

Thanks!

--ryan.

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