memory leak in libio/wfileops.c do_ftell_wide [BZ #17370]

Message ID 20140915011924.GB6586@spoyarek.pnq.redhat.com
State Committed
Headers

Commit Message

Siddhesh Poyarekar Sept. 15, 2014, 1:19 a.m. UTC
  On Sat, Sep 13, 2014 at 03:48:11PM +1000, Allan McRae wrote:
> Do we also need to free this in the error case directly above?

Ugh, yes, thanks for catching that.  Here's a patch to do that.
Tested on x86_64.

Siddhesh

	[BZ #17370]
	* libio/wfileops.c (do_ftell_wide): Free OUT on error path.
  

Comments

Allan McRae Sept. 15, 2014, noon UTC | #1
On 15/09/14 11:19, Siddhesh Poyarekar wrote:
> On Sat, Sep 13, 2014 at 03:48:11PM +1000, Allan McRae wrote:
>> Do we also need to free this in the error case directly above?
> 
> Ugh, yes, thanks for catching that.  Here's a patch to do that.
> Tested on x86_64.
> 
> Siddhesh
> 

Looks good.

Allan

> 	[BZ #17370]
> 	* libio/wfileops.c (do_ftell_wide): Free OUT on error path.
> 
> diff --git a/libio/wfileops.c b/libio/wfileops.c
> index ebc06e8..c5ec5f7 100644
> --- a/libio/wfileops.c
> +++ b/libio/wfileops.c
> @@ -708,7 +708,10 @@ do_ftell_wide (_IO_FILE *fp)
>  		 sequences must be complete since they are accepted as
>  		 wchar_t; if not, then that is an error.  */
>  	      if (__glibc_unlikely (status != __codecvt_ok))
> -		return WEOF;
> +		{
> +		  free (out);
> +		  return WEOF;
> +		}
>  
>  	      offset += outstop - out;
>  	      free (out);
>
  

Patch

diff --git a/libio/wfileops.c b/libio/wfileops.c
index ebc06e8..c5ec5f7 100644
--- a/libio/wfileops.c
+++ b/libio/wfileops.c
@@ -708,7 +708,10 @@  do_ftell_wide (_IO_FILE *fp)
 		 sequences must be complete since they are accepted as
 		 wchar_t; if not, then that is an error.  */
 	      if (__glibc_unlikely (status != __codecvt_ok))
-		return WEOF;
+		{
+		  free (out);
+		  return WEOF;
+		}
 
 	      offset += outstop - out;
 	      free (out);