[FFmpeg-devel] [PATCH] Fix ffserver.c putenv gcc warning

Måns Rullgård mans
Tue Jun 3 01:11:13 CEST 2008


Stefano Sabatini <stefano.sabatini-lala at poste.it> writes:

> On date Friday 2008-05-30 17:21:34 +0100, M?ns Rullg?rd encoded:
>> Stefano Sabatini <stefano.sabatini-lala at poste.it> writes:
>> 
>> > Hi all,
>> >
>> > putenv expects a char* when we feed it with a const char*, this fixes
>> > the resulting warning:
>> > ffserver.c: In function ?main?:
>> > ffserver.c:4388: warning: passing argument 1 of ?putenv? discards qualifiers from pointer target type
> [...]
>
>> > Index: ffserver.c
>> > ===================================================================
>> > --- ffserver.c	(revision 13552)
>> > +++ ffserver.c	(working copy)
>> > @@ -4385,7 +4385,7 @@
>> >  
>> >      parse_options(argc, argv, options, NULL);
>> >  
>> > -    putenv("http_proxy");               /* Kill the http_proxy */
>> > +    putenv(av_strdup("http_proxy"));    /* Kill the http_proxy */
>> 
>> Beautiful memory leak.
>
> Hi.
>
> Is a string left on the heap really a problem?

Yes.

> also the alternative solution (attached) looks quite ugly, also
> keeping the warning doesn't look like a nice solution.
>
> Index: ffserver.c
> ===================================================================
> --- ffserver.c	(revision 13630)
> +++ ffserver.c	(working copy)
> @@ -4372,6 +4372,7 @@
>  int main(int argc, char **argv)
>  {
>      struct sigaction sigact;
> +    char *var = NULL;
>  
>      av_register_all();
>  
> @@ -4385,7 +4386,9 @@
>  
>      parse_options(argc, argv, options, NULL);
>  
> -    putenv("http_proxy");               /* Kill the http_proxy */
> +    var = av_strdup("http_proxy");
> +    putenv(var);                        /* Kill the http_proxy */
> +    av_freep(&var);

This is wrong.  According to specs, putenv() is allowed to keep a
pointer to the string you passed until you pass it a new one for the
same variable name.

-- 
M?ns Rullg?rd
mans at mansr.com




More information about the ffmpeg-devel mailing list