TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

BUG: Memory Leak in code

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
Slysven



Joined: 10 Apr 2011
Posts: 365
Location: As "Jomin al'Bara" in WoTMUD or Wiltshire, UK

PostPosted: Mon Jul 11, 2011 10:14 pm    Post subject: BUG: Memory Leak in code Reply with quote

The new elements of the room and exit data structures are not freed in the corresponding delete functions which are:

line 1881 of mapper.c:
Code:
void delete_room(struct session *ses, int room, int exits)
{
[snip]
   free(ses->map->room_list[room]->name);
   free(ses->map->room_list[room]->color);
   free(ses->map->room_list[room]->symbol);
   free(ses->map->room_list[room]->desc);
   free(ses->map->room_list[room]->area);
   free(ses->map->room_list[room]->note);
/* Missing from 2.00.7 code: */
   free(ses->map->room_list[room]->terrain);
   free(ses->map->room_list[room]->data);
/* End of insert */

   free(ses->map->room_list[room]);

   ses->map->room_list[room] = NULL;

   if (exits)
[snip]
}

line 1958 of mapper.c:
Code:
void delete_exit(struct session *ses, int room, struct exit_data *exit)
{
   free(exit->name);
   free(exit->cmd);
/* Missing from 2.00.7 code: */
   free(exit->data);
/* End of insert */

   UNLINK(exit, ses->map->room_list[room]->f_exit, ses->map->room_list[room]->l_exit)

   free(exit);
}
Obviously these ommissions cause the memory allocated to be lost when the room or exit is deleted which won't be much until the elements are used - I'm moving all the data but my actual note text for the MUD I'm using TinTIn for to the room->data field as I type.
However - I'm running into problems with, I think, the loss of math functions in nest keys... I can't remove selected nested items from the overall variable with either variables or wild cards, for example in the following examples:
Code:
#var notes
#VARIABLE {notes}={{createdby}{Jath}{createdon}{1310167799}{textline1}{A mushroom grows here.}{textline2}{BEWARE Lots of Mother Bears and Cubs in caves south of here.}{textline3}{This room links up to room to south via a couple of voids...}{textlines}{3}{updatedby}{Jath}{updatedon}{1310169116}{version}{0.0.1}}

#unvar notes[textline%*]
#KILL: NO MATCHES FOUND FOR VARIABLE {notes[textline%*]}.

#unvar {notes[textline%*]}
#KILL: NO MATCHES FOUND FOR VARIABLE {notes[textline%*]}.

#format {label} {textline%d} 1
#unvar notes[$label]
#KILL: NO MATCHES FOUND FOR VARIABLE {notes[textline1]}.

#unvar notes[{$label}]
#KILL: NO MATCHES FOUND FOR VARIABLE {notes[{textline1}]}.

#unvar notes[${label}]
#KILL: NO MATCHES FOUND FOR VARIABLE {notes[textline1]}.

#unvar notes[textline1]
#OK. {notes[textline1]} IS NO LONGER A VARIABLE.
Only the last of these worked - want am I (assuming I'm the faulty bit! Confused ) doing wrong?
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3796

PostPosted: Mon Jul 11, 2011 11:17 pm    Post subject: Reply with quote

Thanks for letting me know, I'll fix that for the next release.

Regarding #unvar and regex, I don't think that ever worked. I'll look into it, but as the code is fairly complex and long gone from my memory I don't know how difficult, if possible, it will be.

One alternative is:

Code:

#VARIABLE {notes}={{createdby}{Jath}{createdon}{1310167799}{textline}{{1}{A mushroom grows here.}{2}{BEWARE Lots of Mother Bears and Cubs in caves south of here.}{3}{This room links up to room to south via a couple of voids...}}{updatedby}{Jath}{updatedon}{1310169116}{version}{0.0.1}}

Then to get the total number of lines use: &notes[textline][]
and to erase use: #unvar notes[textline]

Also try:

#unvar {notes[$label]}

There's a bug with a trailing space causing issues that I've been meaning to fix.
Back to top
View user's profile Send private message Send e-mail
Slysven



Joined: 10 Apr 2011
Posts: 365
Location: As "Jomin al'Bara" in WoTMUD or Wiltshire, UK

PostPosted: Tue Jul 12, 2011 9:50 am    Post subject: WORKAROUND: #UNVAR & nested variable Reply with quote

As suspected the
Code:
#UNVARIABLE {notes[$label]}
form didn't work either; but
Code:
#LINE SUBSTITUTE {VARIABLE} #UNVARIABLE {notes[$label]}
does the job!

For what its worth the reason I HAD structured the notes data as I had (with individual lines notes[textline1], notes[textline2], to notes[textlines$notes[textlines]] where notes[textlines] was a small positive integer) was to avoid having nested, nested variables and the possible madness that could lie that way! Embarassed

What I am trying to do is to restructure my existing data so that just the 'notes' text is now stored in the #map roomnote field (so $notes[textline1] becomes roomnote[1], ...) and all the other data is moved to the #map roomdata field. Sort of as you seem to be suggesting! Coffee

Once I've got that sorted I'll post the 'Showing rooms with Notes and/or Special exits' patch to impliment the feature that one or two people have requested that I've got working in my code..!
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3796

PostPosted: Wed Jul 13, 2011 10:26 am    Post subject: Reply with quote

Weird, could be you're running a version that doesn't properly handle variables.

I've got something in mind for handling special exits, just haven't gotten around to it.

I'm planning to use % in the upper left or bottom right corner to indicate a special exit. This will be done using 64 for the exit direction for the upper left mark, and 128 for the exit direction for the bottom right mark, with 64 typically used for in, and 128 for out.

I might add the following pathdirs by default, but haven't made up my mind as of yet.
Code:

#PATHDIR {in} {out} {64}
#PATHDIR {out} {in} {128}


Displaying notes is trickier to handle in a consistent manner. I'll probably let people figure that one out for themselves.
Back to top
View user's profile Send private message Send e-mail
Slysven



Joined: 10 Apr 2011
Posts: 365
Location: As "Jomin al'Bara" in WoTMUD or Wiltshire, UK

PostPosted: Wed Jul 13, 2011 4:54 pm    Post subject: Reply with quote

Here's what I've done to patch mapper.c that puts a '!' in top left of ASCIIgraphic's room display for each room if there is a special (exit->dir == 0) exit in that room and a 'n' if the room->note is non-NULL. Given that I made several different tweaks to that file the line numbers are only approximate!
I also needed to add a "#define MAP_EXIT_SPECIAL (1<<10)" to tintin.h to support these changes:
Code:
@@ -2450,7 +2729,8 @@ char *draw_room(struct session *ses, str
                break;
 
             case 0:
-               continue;
+               door = MAP_EXIT_SPECIAL;
+               break;
          }
 
          SET_BIT(exits, door);
@@ -2459,7 +2739,8 @@ char *draw_room(struct session *ses, str
       switch (line)
       {
          case 1:
-            strcat(buf, HAS_BIT(exits, MAP_EXIT_NW) ? "\\ " : "  ");
+            strcat(buf, HAS_BIT(exits, MAP_EXIT_NW) ? "\\" : " ");
+            strcat(buf, HAS_BIT(exits, MAP_EXIT_SPECIAL) ? "!"  : " ");
             strcat(buf, HAS_BIT(exits, MAP_EXIT_N)  ? "|"   : " ");
             strcat(buf, HAS_BIT(exits, MAP_EXIT_U)  ? "+"   : " ");
             strcat(buf, HAS_BIT(exits, MAP_EXIT_NE) ? "/ "  : "  ");
@@ -2535,7 +2829,8 @@ char *draw_room(struct session *ses, str
          case 3:
             strcat(buf, HAS_BIT(exits, MAP_EXIT_SW) ? "/"   : " ");
             strcat(buf, HAS_BIT(exits, MAP_EXIT_D)  ? "-"   : " ");
-            strcat(buf, HAS_BIT(exits, MAP_EXIT_S)  ? "| "  : "  ");
+            strcat(buf, HAS_BIT(exits, MAP_EXIT_S)  ? "|"  : " ");
+            strcat(buf, (room->note[0]!='\0') ? "n" : " " );
             strcat(buf, HAS_BIT(exits, MAP_EXIT_SE) ? "\\ " : "  ");
             break;
       }

From what you are saying I guess you want to change the '!' to a '%' - given that I tend to play the MUD I'm on with a perminent display of current room information including exits, I just use this symbol as a visual reminder that that particular room on the map has an unusual exit besides the visible normal ones; I'm not quite sure what you mean by 'IN' and 'OUT' here...
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3796

PostPosted: Wed Jul 13, 2011 10:14 pm    Post subject: Reply with quote

What I have in mind would allow placing a % in either the upper left or bottom right corner, which would work well for muds with a standardized in / out exit as you'd be able to see whether you'd go in or out depending on where the % is placed.

Using a '!' for any non standard exit is probably the best general purpose solution, and that'd leave the bottom right corner for a '?' symbol to indicate a note.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Bug Reports All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group