<div dir="ltr">Reviewed-by: Robin Dong <<a href="mailto:sanbai@taobao.com">sanbai@taobao.com</a>></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-07-22 17:13 GMT+08:00 Meng An <span dir="ltr"><<a href="mailto:isolate000@gmail.com" target="_blank">isolate000@gmail.com</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: meng an <<a href="mailto:isolate000@gmail.com">isolate000@gmail.com</a>><br>
<br>
In function trace_read_buffer, the pointer 'buf' is allocated<br>
via xmalloc, but its memory is not released when returns.<br>
<br>
Signed-off-by: Meng An <<a href="mailto:anmeng.an@alibaba-inc.com">anmeng.an@alibaba-inc.com</a>><br>
---<br>
 dog/trace.c |   13 +++++++++----<br>
 1 files changed, 9 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/dog/trace.c b/dog/trace.c<br>
index e3b6248..3c2856b 100644<br>
--- a/dog/trace.c<br>
+++ b/dog/trace.c<br>
@@ -78,6 +78,7 @@ static const char *tracefile = "/tmp/tracefile";<br>
 static int trace_read_buffer(void)<br>
 {<br>
        int ret, tfd;<br>
+       int rval = EXIT_SUCCESS;<br>
        struct sd_req hdr;<br>
        struct sd_rsp *rsp = (struct sd_rsp *)&hdr;<br>
 #define TRACE_BUF_LEN      (1024 * 1024 * 20)<br>
@@ -86,7 +87,8 @@ static int trace_read_buffer(void)<br>
        tfd = open(tracefile, O_CREAT | O_RDWR | O_APPEND | O_TRUNC, 0644);<br>
        if (tfd < 0) {<br>
                sd_err("can't create tracefile");<br>
-               return EXIT_SYSFAIL;<br>
+               rval = EXIT_SYSFAIL;<br>
+               goto out;<br>
        }<br>
<br>
 read_buffer:<br>
@@ -95,22 +97,25 @@ read_buffer:<br>
<br>
        ret = dog_exec_req(&sd_nid, &hdr, buf);<br>
        if (ret < 0)<br>
-               return EXIT_SYSFAIL;<br>
+               rval = EXIT_SYSFAIL;<br>
+               goto out;<br>
<br>
        if (rsp->result == SD_RES_AGAIN)<br>
                goto read_buffer;<br>
<br>
        if (rsp->result != SD_RES_SUCCESS) {<br>
                sd_err("Trace failed: %s", sd_strerror(rsp->result));<br>
-               return EXIT_FAILURE;<br>
+               rval = EXIT_FAILURE;<br>
+               goto out;<br>
        }<br>
<br>
        xwrite(tfd, buf, rsp->data_length);<br>
        if (rsp->data_length == TRACE_BUF_LEN)<br>
                goto read_buffer;<br>
<br>
+out:<br>
        free(buf);<br>
-       return EXIT_SUCCESS;<br>
+       return rval;<br>
 }<br>
<br>
 static int trace_enable(int argc, char **argv)<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.1<br>
<br>
--<br>
sheepdog mailing list<br>
<a href="mailto:sheepdog@lists.wpkg.org">sheepdog@lists.wpkg.org</a><br>
<a href="http://lists.wpkg.org/mailman/listinfo/sheepdog" target="_blank">http://lists.wpkg.org/mailman/listinfo/sheepdog</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>--<br>Best Regard<br>Robin Dong
</div>