diff mbox

[2/2] libxl: Do not leak data on error path from libxl__read_sysfs_file_contents

Message ID 1459782600-16073-2-git-send-email-ian.jackson@eu.citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Ian Jackson April 4, 2016, 3:10 p.m. UTC
Bug introduced in bc023ecd
"libxl_utils: add internal function to read sysfs file contents"

CID: 1358108
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
CC: coverity@xenproject.org
CC: Chunyan Liu <cyliu@suse.com>
---
 tools/libxl/libxl_utils.c |    1 +
 1 file changed, 1 insertion(+)

Comments

Chunyan Liu April 7, 2016, 8:16 a.m. UTC | #1
>>> On 4/4/2016 at 11:10 PM, in message
<1459782600-16073-2-git-send-email-ian.jackson@eu.citrix.com>, Ian Jackson
<ian.jackson@eu.citrix.com> wrote: 
> Bug introduced in bc023ecd 
> "libxl_utils: add internal function to read sysfs file contents" 
>  
> CID: 1358108 
> Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com> 
> CC: coverity@xenproject.org 
> CC: Chunyan Liu <cyliu@suse.com> 
> --- 
>  tools/libxl/libxl_utils.c |    1 + 
>  1 file changed, 1 insertion(+) 
>  
> diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c 
> index ceb8825..bd58a52 100644 
> --- a/tools/libxl/libxl_utils.c 
> +++ b/tools/libxl/libxl_utils.c 
> @@ -466,6 +466,7 @@ int libxl__read_sysfs_file_contents(libxl__gc *gc, const  
> char *filename, 
>      e = errno; 
>      assert(e != ENOENT); 
>      if (f) fclose(f); 
> +    free(data); 

'data' is malloced with 'gc', it'll be freed by GC_FREE. Do we need to free
it here?

Chunyan

>      return e; 
>  } 
>
Ian Jackson April 7, 2016, 5:03 p.m. UTC | #2
Chun Yan Liu writes ("Re: [PATCH 2/2] libxl: Do not leak data on error path from libxl__read_sysfs_file_contents"):
> <1459782600-16073-2-git-send-email-ian.jackson@eu.citrix.com>, Ian Jackson
> <ian.jackson@eu.citrix.com> wrote: 
> > +    free(data); 
> 
> 'data' is malloced with 'gc', it'll be freed by GC_FREE. Do we need to free
> it here?

Oh, you are quite right.  My patch was wrong.

Thanks,
Ian.
diff mbox

Patch

diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
index ceb8825..bd58a52 100644
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -466,6 +466,7 @@  int libxl__read_sysfs_file_contents(libxl__gc *gc, const char *filename,
     e = errno;
     assert(e != ENOENT);
     if (f) fclose(f);
+    free(data);
     return e;
 }