Re: Quick save tell snippet.

From: Carlo Mocci (mocci@TIN.IT)
Date: 04/01/98


At 16.30 01/04/98 -0600, you wrote:
>> 1) Don't we need to check if a pointer exists before freeing it ?
>> >+    if(counter==9) {
>> >+      /* then we don't want the old one anymore.. */
>> >>>>      if (GET_TELLS(ch,i)) free(GET_TELLS(ch,counter));
>> >+    }
>>
>> 2) We need to add in free_char (db.c) a for cycle for freeing the allocated
>> strings previous_tells...
>> Am I right ???
>
>You sure are. :)  This must have been why I didn't release it :)  Gosh,
>I'm glad I had written this so long ago, else I'd be embarassed.  Curious
>why it didn't crash when it tried to free a null pointer, but I'll let
>that go for now.  You really ought to free up the tells when the character
>quits, probably in db.c, but maybe not - I'd put it in extract_character,
>but thats called when the pc dies and I'd rather keep them through it if I
>were me.
I've freed the previous_tells in db.c in free_char:

void free_char(struct char_data * ch)
{
  int i;
  struct alias *a;

......

    if (ch->player_specials->poofin)
      free(ch->player_specials->poofin);
    if (ch->player_specials->poofout)
      free(ch->player_specials->poofout);
    for (i=0; i < TELLS_STORED; i++)
      if (ch->player_specials->previous_tells[i])
        free(ch->player_specials->previous_tells[i]);
    free(ch->player_specials);
.....

My idea was of freeing at the same time all that was stored in
player_specials (aliases, poofin, poofout and now also previous_tells).
The TELLS_STORED is defined as 10 now, but that way (and also in other
parts of the code of course) I can easily modify the number of messages I
want to store.


KABIR
Coder of DALILAMUD
dalila.shopitaly.net 4000
---------------------------------------------------------------
|        __         __            __  __         __       __  |
|   __  (  )  ___  (  )    __    (  \/  )  __   / _)  __ (  ) |
|  / _) /__\ (  ,)  )(__  /  \    )    (  /  \ ( (_  / _) )(  |
| ( (_ (_)(_) )  \ (____)( () )  (_/\/\_)( () ) \__)( (_ (__) |
|  \__)      (_)\_)       \__/            \__/       \__)     |
|                                                             |
| mailto: mocci@tin.it                                        |
| http://volftp.tin.it/IT/IT/ITALIANI/MOCCI                   |
| http://www.geocities.com/SunsetStrip/Palms/7010             |
---------------------------------------------------------------


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST