Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2002:
[Freeciv-Dev] Re: Wonder obsolesence across games (PR#1434)
Home

[Freeciv-Dev] Re: Wonder obsolesence across games (PR#1434)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Mike Kaufman <kaufman@xxxxxxxxxxxxxxxxxxxxxx>, freeciv-dev@xxxxxxxxxxx, bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: Wonder obsolesence across games (PR#1434)
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 16 May 2002 14:35:33 +0200
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Thu, May 16, 2002 at 11:19:00AM +0100, Ben Webb wrote:
> On Wed, May 15, 2002 at 10:09:45PM +0200, Raimar Falke wrote:
> > Here is a second fix. There are no additional memory leaks by calling
> > game_init.
> 
> > -  geff_vector_init(&game.effects);
> > -  ceff_vector_init(&game.destroyed_effects);
> > +  geff_vector_reinit(&game.effects);
> > +  ceff_vector_reinit(&game.destroyed_effects);
> 
>       This is bad. The first time you call game_init you are calling
> _reinit on something that hasn't yet been initialized! (Your later patch
> obviously suffers from exactly the same problem.) Plus, you're still not
> dealing with player.effects properly (well, at all). The _init function
> is supposed to be used to, er, initialize your specvec type. If you
> don't call it before using the type (which is what your patch is doing)
> then you're going to get undefined behaviour. (It's only luck that is
> saving you at the moment - these two types just happen to be globals, so
> start off as NULL, which just happens with the _current_ implementation of
> athing to be what ath_init sets them to.)
> 
> > +void SPECVEC_FOO(_vector_reinit) (SPECVEC_VECTOR * tthis)
> > +{
> > +  if (SPECVEC_FOO(_vector_size) (tthis)) {
> > +    SPECVEC_FOO(_vector_free) (tthis);
> > +  }
> > +  SPECVEC_FOO(_vector_init) (tthis);
> > +}
> > +
> 
>       This function is redundant, as _vector_free already does this.
> You need proper functions to free your types at game end, not nasty
> hacks; the former will be able to deal with your vectors requiring
> freeing of instance data. I have submitted patches to this thread
> that address these issues already. You can still go and call game_init
> if you really want to; it should just be redundant.

Ok I agree that the proposed solution was too fragile. What about this
one?

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
  (On the statement print "42 monkeys"+"1 snake"): BTW, both perl and Python
  get this wrong. Perl gives 43 and Python gives "42 monkeys1 snake", when 
  the answer is clearly "41 monkeys and 1 fat snake".  
    -- Jim Fulton, 10 Aug 1999

Attachment: reinit3.diff
Description: Text document


[Prev in Thread] Current Thread [Next in Thread]