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.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ SMAUG ➜ SMAUG coding ➜ Is this code okay? (mem leaks etc)

Is this code okay? (mem leaks etc)

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


Posted by Zeno   USA  (2,871 posts)  Bio
Date Wed 27 Jun 2007 01:58 PM (UTC)

Amended on Wed 27 Jun 2007 02:07 PM (UTC) by Zeno

Message
I plan to release this to the public, I just want to make sure it's okay before I do so. (No mem leaks, etc)

In act_comm.c at the top:
char * contact1;
char * contact2;
char * contact3;
char * contact4;
char * contact5;
char * contact6;
char * contact7;
char * contact8;


In talk_channel at the top:
    char histbuf[MAX_STRING_LENGTH];

In the talk_channel CONTACT case:
        sprintf( buf, "&R[&O%s&R] &W$n &w- '&Y$t%s&w'&D", verb, ANSI_RESET );
        strtime                    = ctime( &current_time );
        strtime[strlen(strtime)-1] = '\0';
        sprintf(histbuf, "&g(%s) &W%s: &Y%s&D\n\r", strtime, ch->name, argument);
        contact8 = contact7;
        contact7 = contact6;
        contact6 = contact5;
        contact5 = contact4;
        contact4 = contact3;
        contact3 = contact2;
        contact2 = contact1;
        contact1 = str_dup(histbuf);
        break;


That's it. Everthing else is just stuff to display it etc. (This is a channel history)

I'm just not totally sure if I should have used str_dup or STRFREE somewhere else, or the sort.

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #1 on Wed 27 Jun 2007 02:35 PM (UTC)
Message
You don't free the memory you allocate with the str_dup. When you set contact8 to contact7, you probably want to clear whatever contact8 contains (if it contains something already). I don't think you need to care too much about emptying the strings on shutdown unless you are a compulsive perfectionist. (I'd do it, but that's just me...) But freeing the contents of contact8 when you lose the pointer is pretty important.

Incidentally, why didn't you make 'contact' an array? :)

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Zeno   USA  (2,871 posts)  Bio
Date Reply #2 on Wed 27 Jun 2007 02:44 PM (UTC)
Message
So I should DISPOSE contact8? Is that it?

As for the array, yeah I planned to redo it into one before I release it.

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #3 on Wed 27 Jun 2007 03:08 PM (UTC)
Message
Yes, I think that disposing of contact8 when you're about to overwrite it is all you need to do. Just make sure that there's actually a string there before overwriting it. (That would mean you'd have to initialize all of them to NULL beforehand.)

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Gohan_TheDragonball   USA  (183 posts)  Bio
Date Reply #4 on Thu 28 Jun 2007 12:14 AM (UTC)
Message
http://www.mudbytes.net/index.php?a=files&s=viewfile&fid=960
Top

Posted by Zeno   USA  (2,871 posts)  Bio
Date Reply #5 on Thu 28 Jun 2007 12:45 AM (UTC)
Message
Silly me. I didn't think there was a chan history snippet for Smaug released.

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
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,935 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.