[MPlayer-dev-eng] [PATCH][BUG] Incorrect memleak fix code in input/input.c might cause incorrect free
Shachar Raindel
shacharr at gmail.com
Mon Jul 26 11:21:52 CEST 2004
On Mon, 26 Jul 2004 11:10:41 +0200, Moritz Bunkus <moritz at bunkus.org> wrote:
> Hi,
>
> > - file = config_file[0] != '/' ? get_path(config_file) : config_file;
> > + tmpbufptr = get_path(config_file);
> > + file = config_file[0] != '/' ? tmpbufptr : config_file;
>
> ....
>
> Why not just use
> file = config_file[0] != '/' ? get_path(config_file) : strdup(config_file);
> ?
>
> Mosu
>
A. The C standard doesn't guarantee in a ternary operator that only
one of the expressions will be executed. It might as well evaluate
both, but take only the second one => Memory leak.
B. It adds unneeded string duplication, which can be avoided in the
cost of few more lines (not to speak about the fact that the existing
patch already has memory leak if it fails in opening file)
Cheers,
Shachar
More information about the MPlayer-dev-eng
mailing list