I'll try to explain, as I cant find any CLEAR on-line doco outlining what I mean.

Its up to you to point out any flaws in my argument, as this is MY logical interpretation of how malloc/free work.

AFAIK, "malloc(size)" allocates a single block of memory, regardless of the FORMULA used to calculate 'size'. (FYI - your formula looks fine to me)

So malloc itself, doesnt know or care what size chunks you are going to be using it in. ie - sizeof(PLAYER_SCORE_STRUCT)

So if you say "free(playScoreArr[6]);", how does it know how many bytes to delete?

I would guess the free either fails, or it frees the REST of the block, starting at "playScoreArr[6]". I suspect this is the case...
eg1.
You are trying to free "playScoreArr[numOfRecords-2]", but it is actually freeing "playScoreArr[numOfRecords-2]" AND "playScoreArr[numOfRecords-1]",
so when you later try to free "playScoreArr[numOfRecords-1]", its already been freed, and generates the error.
eg2.
You are trying to free "playScoreArr[2352]", but it is actually freeing "playScoreArr[2352]" RIGHT THROUGH TO "playScoreArr[numOfRecords-1]".
So when you later try to free "playScoreArr[higher-than-2352]", its already been freed, and generates the error.

How does that fit the behaviour you are suffering from?



"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial