[sheepdog] [PATCH v1] dog: memory leak in trace_read_buffer

Robin Dong robin.k.dong at gmail.com
Tue Jul 22 11:24:40 CEST 2014


Reviewed-by: Robin Dong <sanbai at taobao.com>


2014-07-22 17:13 GMT+08:00 Meng An <isolate000 at gmail.com>:

> From: meng an <isolate000 at gmail.com>
>
> In function trace_read_buffer, the pointer 'buf' is allocated
> via xmalloc, but its memory is not released when returns.
>
> Signed-off-by: Meng An <anmeng.an at alibaba-inc.com>
> ---
>  dog/trace.c |   13 +++++++++----
>  1 files changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/dog/trace.c b/dog/trace.c
> index e3b6248..3c2856b 100644
> --- a/dog/trace.c
> +++ b/dog/trace.c
> @@ -78,6 +78,7 @@ static const char *tracefile = "/tmp/tracefile";
>  static int trace_read_buffer(void)
>  {
>         int ret, tfd;
> +       int rval = EXIT_SUCCESS;
>         struct sd_req hdr;
>         struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
>  #define TRACE_BUF_LEN      (1024 * 1024 * 20)
> @@ -86,7 +87,8 @@ static int trace_read_buffer(void)
>         tfd = open(tracefile, O_CREAT | O_RDWR | O_APPEND | O_TRUNC, 0644);
>         if (tfd < 0) {
>                 sd_err("can't create tracefile");
> -               return EXIT_SYSFAIL;
> +               rval = EXIT_SYSFAIL;
> +               goto out;
>         }
>
>  read_buffer:
> @@ -95,22 +97,25 @@ read_buffer:
>
>         ret = dog_exec_req(&sd_nid, &hdr, buf);
>         if (ret < 0)
> -               return EXIT_SYSFAIL;
> +               rval = EXIT_SYSFAIL;
> +               goto out;
>
>         if (rsp->result == SD_RES_AGAIN)
>                 goto read_buffer;
>
>         if (rsp->result != SD_RES_SUCCESS) {
>                 sd_err("Trace failed: %s", sd_strerror(rsp->result));
> -               return EXIT_FAILURE;
> +               rval = EXIT_FAILURE;
> +               goto out;
>         }
>
>         xwrite(tfd, buf, rsp->data_length);
>         if (rsp->data_length == TRACE_BUF_LEN)
>                 goto read_buffer;
>
> +out:
>         free(buf);
> -       return EXIT_SUCCESS;
> +       return rval;
>  }
>
>  static int trace_enable(int argc, char **argv)
> --
> 1.7.1
>
> --
> sheepdog mailing list
> sheepdog at lists.wpkg.org
> http://lists.wpkg.org/mailman/listinfo/sheepdog
>



-- 
--
Best Regard
Robin Dong
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wpkg.org/pipermail/sheepdog/attachments/20140722/1a6adf74/attachment-0004.html>


More information about the sheepdog mailing list