thiefControl in 2.2 leaks memory

Questions, comments, and news on the server side plug-ins and it's API
Post Reply
Enigma
Private First Class
Private First Class
Posts: 212
Joined: Sat Apr 23, 2005 3:13 am

thiefControl in 2.2 leaks memory

Post by Enigma »

Code: Select all

void ThiefControl::process( bz_EventData *eventData )
 {
   bz_FlagTransferredEventData_V1 *data = (bz_FlagTransferredEventData_V1 *) eventData;
   bz_BasePlayerRecord *playerFrom = bz_getPlayerByIndex(data->fromPlayerID);
   bz_BasePlayerRecord *playerTo = bz_getPlayerByIndex(data->toPlayerID);
 
   if (eventData) {
     switch (eventData->eventType) {
     case bz_eFlagTransferredEvent:
 
       if (playerFrom && playerTo) {
 	if ((playerTo->team != eRogueTeam || bz_getGameType() == eRabbitGame) && playerFrom->team == playerTo->team) {
 	  data->action = data->DropThief;
 	  bz_sendTextMessage(BZ_SERVER, data->toPlayerID, "Flag dropped. Don't steal from teammates!");
 	}
       }
       break;
     default:
       break;
     }
   }
 }


It never calls bz_freePlayerRecord, and since that function is still there, I will assume the API does not use smart pointers.


I went ahead and rewrote the plugin in an attempt to make it slightly better, as based on my experience playing BZFlag while the plugin is loaded. Hopefully everyone will like my changes (or at least a few people).

Please note that it was not tested, but it compiled the first time I tried (somewhat rare for me). Maybe I will test it tomorrow.
Attachments
thiefControl.cpp
(3.48 KiB) Downloaded 345 times
User avatar
macsforme
General
General
Posts: 2069
Joined: Wed Mar 01, 2006 5:43 am

Post by macsforme »

Submit this to the patches section on SourceForge, perhaps?

http://sourceforge.net/tracker/?group_i ... tid=303248

EDIT: As for the lack of a freePlayerRecord() call, I believe that in the 2.1 code that method is called in the class destructor, so it's no longer necessary.
Thumper
Private First Class
Private First Class
Posts: 34
Joined: Tue Sep 28, 2004 9:22 pm
Location: Toronto, Ontario, Canada
Contact:

Modified patch applied

Post by Thumper »

I modified this patch to allow stealing any team flag (not just your own) and applied it to trunk.
User avatar
JeffM
Staff Sergeant
Staff Sergeant
Posts: 5196
Joined: Fri Dec 13, 2002 4:11 am

Post by JeffM »

bz_freePlayerRecord needs to be called any time that the plug-in itself calls a function that returns a player record. This is so that BZFS can know that the plug-in is done with the record and can release it.

in 2.1 some events now have a member variable that is a pointer to a player record. These records are not returned by api functions, but are part of the internal event data. They should NOT be freed by the plug in, as they can and will be used by other plug-ins. BZFS will take care of releasing those records when all the event callbacks are terminated.
ImageJeffM
Enigma
Private First Class
Private First Class
Posts: 212
Joined: Sat Apr 23, 2005 3:13 am

Re: Modified patch applied

Post by Enigma »

Thumper wrote:I modified this patch to allow stealing any team flag (not just your own) and applied it to trunk.

Oops. That's what I meant to do. :oops:
Post Reply