Ok.

if (!str_cmp (word, "Bestname"))
{
        tmp = fread_string (fp);
        strcpy (bfield_data.best_ratio.name, tmp);
        free_string (tmp);
        fMatch = TRUE;
        break;
}

Correct?

Can I then use tmp again at a different point without running into trouble?
I.E. later:

if (!str_cmp (word, "Mostkname"))
{
    tmp = fread_string (fp);
    strcpy(bfield_data.most_kills.name, tmp);
    free_string(tmp);
    fMatch = TRUE;
    break;
}


----- Original Message -----
From: "Michael Barton" <[EMAIL PROTECTED]>
To: "Jeremy Hill" <[EMAIL PROTECTED]>; "Edwin Groothuis" <[EMAIL PROTECTED]>
Cc: <[email protected]>
Sent: Thursday, July 11, 2002 11:42 PM
Subject: Re: reading from files, fread_string


> > strcpy (bfield_data.best_ratio.name, fread_string (fp));
> >
> > Or did you mean:
> >
> > char *tmp;
> > tmp = fread_string (fp);
> > strcpy (bfield_data.best_ratio.name, tmp);
> >
> > Actually, those two above may more or less do the same thing.
>
> Yes and no.  In the first case, you have a memory leak.
> In the second case, you still have tmp to free_string after you've copied
> it.
>
> --Palrich.
>
>
>
> --
> ROM mailing list
> [email protected]
> http://www.rom.org/cgi-bin/mailman/listinfo/rom


Reply via email to