Thread 'magic' is not correct!

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
User avatar
SWAT
Insane DCEmu
Insane DCEmu
Posts: 191
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Sat Jan 31, 2004 2:34 pm
Location: Russia/Novosibirsk
Has thanked: 1 time
Been thanked: 0
Contact:

Thread 'magic' is not correct!

Post by SWAT »

Hi!
I have some errors at freeing memory, and not understand way this hapen.

Code: Select all

Thread 1/8c02943a freeing block @ 8c8e6038
  'magic' is not correct! 8c8e6af8
Thread 1/8c029474 freeing block @ 8c8e6038
  'magic' is not correct! 8c8e6af8
Thread 1/8c02943a freeing block @ 8c8e6038
  'magic' is not correct! 8c8e6af8
Thread 1/8c02943a freeing block @ 8c58d0f8
  'magic' is not correct! 8c58dbb8
Thread 1/8c029474 freeing block @ 8c58d0f8
  'magic' is not correct! 8c58dbb8
Thread 1/8c02943a freeing block @ 8c58d0f8
  'magic' is not correct! 8c58dbb8
Thread 1/8c02943a freeing block @ 8c4162f0
  'magic' is not correct! 8c58c4c8
Thread 1/8c029474 freeing block @ 8c4162f0
Memory is allocated and freed in one thread.
Image
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5652
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Thread 'magic' is not correct!

Post by BlueCrab »

The "Thread 1" part is just saying that the memory was being freed in Thread 1. That string of errors basically means that you've got something writing somewhere where it definitely shouldn't be. Its also possible that the error is caused by something like freeing memory that was never allocated in the first place.

Basically, how those errors are detected are as follows. When you pass a chunk of memory into free, it checks a tag that should have been added by malloc before the block of memory. This tag is 256 bytes in length, and includes various data about it. The 'magic' referred to in the error is the first entry in that 256 byte area. So, somehow something overwrote the first 4 bytes of an area that should never be touched in memory (since you shouldn't have any pointers to it).

If you want a more detailed look at it, look in the malloc.c file in kos/kernel/libc/koslib, and look for the public_fREe() function and follow it around a bit in the code. The function you're looking for should start on line 1735 of that file (at least in the current SVN it does).
User avatar
SWAT
Insane DCEmu
Insane DCEmu
Posts: 191
Joined: Sat Jan 31, 2004 2:34 pm
Location: Russia/Novosibirsk
Has thanked: 1 time
Been thanked: 0
Contact:

Re: Thread 'magic' is not correct!

Post by SWAT »

I see... Thanks!
I saw this file, just thought that the memory can be damaged.
This means that nothing bad happened, just the memory apparently freed 2 times instead of 1?
Image
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5652
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Thread 'magic' is not correct!

Post by BlueCrab »

Double-freeing is one possible way to cause that issue. You could also be freeing an invalid pointer, or it could be that you've written beyond the end (or beginning) of a buffer.

No matter what the issue is, you definitely have a problem in your code if you're getting those messages.
User avatar
SWAT
Insane DCEmu
Insane DCEmu
Posts: 191
Joined: Sat Jan 31, 2004 2:34 pm
Location: Russia/Novosibirsk
Has thanked: 1 time
Been thanked: 0
Contact:

Re: Thread 'magic' is not correct!

Post by SWAT »

I found a bug, memory is freed multiple times. Thanks for your help!
Image
Post Reply