Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ Programming ➜ General ➜ [*****] BUG: Attempt to recyle invalid memory of size 1024 -> recycle.c:705

[*****] BUG: Attempt to recyle invalid memory of size 1024 -> recycle.c:705

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Trom   (82 posts)  Bio
Date Mon 30 May 2005 05:05 PM (UTC)

Amended on Mon 30 May 2005 05:10 PM (UTC) by Trom

Message

void free_buf ( BUFFER * buffer )
{
    if ( !IS_VALID ( buffer ) )
        return;

	if ( buffer == NULL )
		return;

    free_mem ( buffer->string, buffer->size );
    buffer->string = str_dup("\0");
    buffer->size = 0;
    buffer->state = BUFFER_FREED;
    INVALIDATE ( buffer );

    buffer->next = buf_free;
    buf_free = buffer;
}


The line in bold is line 705 of recycle.h. I've checked google for any possible solutions, one guy from mudmagic said try using str_dup for the strings so i changed all values sent to the problem buffer->string through str_dup. It didn't do anything.

Please help, i've spent much time trying to figure this one out (not really getting the whole magic number thing).

The below is whats left of the string after i've started using str_dup on it (used visual c++ 6 to find the lines).


Searching for '->string ='...
C:\cygwin\home\t14\src\recycle.c(663):    buffer->string = alloc_mem ( buffer->size );
C:\cygwin\home\t14\src\recycle.c(664):    buffer->string = str_dup("\0");
C:\cygwin\home\t14\src\recycle.c(690):    buffer->string = alloc_mem ( buffer->size );
C:\cygwin\home\t14\src\recycle.c(691):    buffer->string = str_dup("\0");
C:\cygwin\home\t14\src\recycle.c(706):    buffer->string = str_dup("");
C:\cygwin\home\t14\src\recycle.c(745):        buffer->string = alloc_mem ( buffer->size );
C:\cygwin\home\t14\src\recycle.c(757):    buffer->string = str_dup("\0");
7 occurrence(s) have been found.


Before the above changes it was buffer->string[0] = "\0" which made me think the change to str_dup maybe the correct change, but it made no difference.. The line with buffer->string = str_dup("") used to be buffer->string = NULL.
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #1 on Mon 30 May 2005 07:06 PM (UTC)
Message
http://www.mudmagic.com/boards/bases/4/7091/7107
Looks like it addresses your problem.

Also, you should be using single quotes around all your null characters. Since they are characters, and not strings. No idea if that will solve the problem by itself, but that's definately a bug.

Basically what I think (as I don't have the ROM source (is this rom? You didnt specify) handy) you're doing is just setting the strings to zero length (their first character is a null) which wouldn't matter (as far as I am aware) if you're just setting the 0th character to null, or if you use strdup.
Those line's should have been string->buffer = '\0' though.

But your problem is obviously before that line, have you tried debuging it? I imagine you'll find something blatantly wrong when you're calling free_mem.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by Trom   (82 posts)  Bio
Date Reply #2 on Mon 30 May 2005 09:48 PM (UTC)

Amended on Mon 30 May 2005 09:49 PM (UTC) by Trom

Message
Yes i went through the code quite a bit. When someone quits the mud crashes. I'm going to check the link and change the double quotes to single to see if that stops the problem. Will post back results by tonight most likely.

Using rom 2.4 and rot 1.4 base code. Its heavily modified, but as to recycling memory and such, its not changed.
Top

Posted by Trom   (82 posts)  Bio
Date Reply #3 on Mon 30 May 2005 10:46 PM (UTC)

Amended on Mon 30 May 2005 10:47 PM (UTC) by Trom

Message
Just tried your suggestion the following ways:

buffer->string = '\0';
buffer->string = str_dup('\0');

They both resulted in a d/c when someone types in a username that exists (doesn't reach password, mud
is no longer running).

buffer->string[0] = '\0';

This is how it was before i changed anything and it continues to do the same thing as the following:

buffer->string = str_dup("\0");
buffer->string = str_dup("");

The problem still exists were someone tries to logout and the mud crashes. It is directly related with free_mem()'ing the buffer->string variable. I've read the forum link you gave that suggests that free_string() can only be done once. Still not entirely sure what has to be done now. Any more ideas?

When someone logs in it also shows the attempt to recyle bug in server log, but doesn't crash/disconnect the mud.
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #4 on Tue 31 May 2005 06:38 AM (UTC)

Amended on Tue 31 May 2005 06:54 AM (UTC) by Flannel

Message
Alright, I broke down and downloaded it.
(Read the second edit first, then come back and read through).


That error message happens when your magic number isnt correct. You pass two arguments to free_mem, a void pointer, and an int. The void pointer (your string) is cast to an int pointer, and then that is checked against the magic number (this is all about line 2635ish in db.c).

The magic number (as I understand it) is at the beginning of the buffer, it acts as a checksum sort of thing (because if something overflows, the number will be different). And that's whats happening. Your number is wrong.

As for why, I'm not certain, I'm not familiar with ROM, so I have no idea how the buffer is structured. You could be writing over it with the null, or with some other write.

You'll want to do string = str_dup('\0') (no, you won't read the edits).
But you definately want to use single quotes when dealing with null characters, since it's a character, not a string.

Free_string just does some checking, and then free_mems the string. You don't want to do that (I think) because you're dealing with a buffer, not a string.

Now that I've done some poking around (yeah, this post has taken me two hours from start to finish), str_dup copies a string into dynamic memory. So, I'm not entirely sure why you were told to do that in the first place.
And since this is so long, I'm going to post (I'll probably post again in a little) before I accidentally hit back.

Edit:
Actually, it occured to me why we're setting that. Because we don't want to leave the pointer dangling.
However, that shouldn't be causing this (unless I'm missing something). I've changed my statement in the post to reflect this.
You should definately be using the single quotes though.

Edit (another one):
In my version (of the source), it just sets buffer->string to NULL (string = NULL), this makes sense. Since, otherwise we're allocating one byte for our 'empty' buffer. Which doesn't make sense.
So, I suggest that.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by Trom   (82 posts)  Bio
Date Reply #5 on Tue 31 May 2005 01:32 PM (UTC)
Message
I'm going to attempt to set them using '= NULL' and see if that helps, thanks for taking the time to go into this too :)
Top

Posted by Trom   (82 posts)  Bio
Date Reply #6 on Tue 31 May 2005 01:38 PM (UTC)

Amended on Tue 31 May 2005 04:40 PM (UTC) by Trom

Message
Amazing, you must be a genius or something! The bug is fixed thank you very much :)

Too clearify for those who had this same problem:

[code]
Searching for '->string ='...
C:\cygwin\home\t14\src\recycle.c(663): buffer->string = alloc_mem ( buffer->size );
C:\cygwin\home\t14\src\recycle.c(664): buffer->string = str_dup("\0");
C:\cygwin\home\t14\src\recycle.c(690): buffer->string = alloc_mem ( buffer->size );
C:\cygwin\home\t14\src\recycle.c(691): buffer->string = str_dup("\0");
C:\cygwin\home\t14\src\recycle.c(706): buffer->string = str_dup("");
C:\cygwin\home\t14\src\recycle.c(745): buffer->string = alloc_mem ( buffer->size );
C:\cygwin\home\t14\src\recycle.c(757): buffer->string = str_dup("\0");
7 occurrence(s) have been found.
[/code]

Whatever you had, search for '->string =' and change it to this

[code]
Searching for '->string ='...
C:\cygwin\home\t14\src\recycle.c(663): buffer->string = alloc_mem ( buffer->size );
C:\cygwin\home\t14\src\recycle.c(664): buffer->string = NULL;
C:\cygwin\home\t14\src\recycle.c(690): buffer->string = alloc_mem ( buffer->size );
C:\cygwin\home\t14\src\recycle.c(691): buffer->string = NULL;
C:\cygwin\home\t14\src\recycle.c(706): buffer->string = NULL;
C:\cygwin\home\t14\src\recycle.c(745): buffer->string = alloc_mem ( buffer->size );
C:\cygwin\home\t14\src\recycle.c(757): buffer->string = NULL;
7 occurrence(s) have been found.
[/code]

The buffer->string was being emptied unproperly. Using NULL clears it without crashing the mud.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


19,555 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.