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

SDL_malloc.c - bug in allocation #302

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

SDL_malloc.c - bug in allocation #302

SDLBugzilla opened this issue Feb 10, 2021 · 0 comments

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

Reported in version: 1.2.11
Reported for operating system, platform: Linux, x86

Comments on the original bug report:

On 2007-05-15 08:12:19 +0000, Alex wrote:

When memory routines from SDL_malloc.c are used, memory allocation may fail without apparent reasons (despite enough memory available). Subsequent allocations usually succeed.

In my case it was showing up only with SDL_mixer, but I believe it's generic and just triggered by some allocation/deallocation patterns specific to SDL_mixer.

After a bit of debugging, it seems to me that the problem originates from not considering the overhead due to alignment requirements in sys_alloc().

I.e., say

asize = granularity_align(nb + TOP_FOOT_SIZE + SIZE_T_ONE);

@line 3411 - sys_alloc()

Later, the actual usable size may become smaller, because of alignment:

size_t offset = align_offset(chunk2mem(p));
p = (mchunkptr)((char*)p + offset);
psize -= offset;

@lines 3231-3233 in init_top()

In my case, the problem seemed to go away when adding MALLOC_ALIGNMENT in all such calculations in sys_alloc(), like

asize = granularity_align(nb + TOP_FOOT_SIZE + MALLOC_ALIGNMENT + SIZE_T_ONE);

To ensure that size is (at least) enough after applying alignment. I'm not sure it's the best solution though.

On 2007-06-02 13:59:02 +0000, Ryan C. Gordon wrote:

Bumping a bunch of bugs to Priority 1 for consideration for the 1.2.12 release.

--ryan.

On 2007-06-14 23:09:23 +0000, Sam Lantinga wrote:

Is there any chance you can give a simple test case to reproduce the problem? Or lacking that, a step by step trace through the function showing all variable values?

Thanks!

On 2007-07-15 15:16:22 +0000, Sam Lantinga wrote:

Date: Sun, 15 Jul 2007 17:55:33 -0400
From: Doug Lea
To: Sam Lantinga slouken@devolution.com
Subject: Re: SDL_malloc.c bug details (fwd)

A first pass diagnosis is that when alignment is greater than reserved footer space, further padding is necessary. (A quick fix is just to add one alignment's worth to request size, but it is likely that this can be reduced with some thought.)

-Doug

On 2007-07-15 17:11:23 +0000, Sam Lantinga wrote:

The suggested fix was approved by Doug Lea and checked into subversion. "overkill, but safe" He's going to have a new release of his malloc implementation sometime next month and I'll use that when it's released.

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