From: "Zhang, Chen" <chen.zhang@intel.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>
Cc: Jason Wang <jasowang@redhat.com>,
qemu-dev <qemu-devel@nongnu.org>,
Li Zhijian <lizhijian@cn.fujitsu.com>,
Zhang Chen <zhangckid@gmail.com>
Subject: Re: [Qemu-devel] [PATCH V3] net/colo-compare.c: Fix memory leak and code style issue.
Date: Fri, 19 Jul 2019 01:56:21 +0000 [thread overview]
Message-ID: <9CFF81C0F6B98A43A459C9EDAD400D78061D0429@shsmsx102.ccr.corp.intel.com> (raw)
In-Reply-To: <664c3b23-4d19-cda6-dbd7-4a7195a96ec3@redhat.com>
> -----Original Message-----
> From: Philippe Mathieu-Daudé [mailto:philmd@redhat.com]
> Sent: Thursday, July 18, 2019 6:54 PM
> To: Peter Maydell <peter.maydell@linaro.org>
> Cc: Zhang, Chen <chen.zhang@intel.com>; Li Zhijian <lizhijian@cn.fujitsu.com>;
> Jason Wang <jasowang@redhat.com>; qemu-dev <qemu-devel@nongnu.org>;
> Zhang Chen <zhangckid@gmail.com>
> Subject: Re: [Qemu-devel] [PATCH V3] net/colo-compare.c: Fix memory leak
> and code style issue.
>
> On 7/18/19 12:37 PM, Peter Maydell wrote:
> > On Thu, 18 Jul 2019 at 11:28, Philippe Mathieu-Daudé <philmd@redhat.com>
> wrote:
> >>
> >> On 7/18/19 11:22 AM, Zhang Chen wrote:
> >>> From: Zhang Chen <chen.zhang@intel.com>
> >>>
> >>> This patch to fix the origin "char *data" menory leak, code style
> >>> issue
> >>
> >> "memory"
Oh, I will fix this typo in next version.
> >>
> >>> and add necessary check here.
> >>> Reported-by: Coverity (CID 1402785)
> >>>
> >>> Signed-off-by: Zhang Chen <chen.zhang@intel.com>
> >>> ---
> >>> net/colo-compare.c | 28 +++++++++++++++++++++-------
> >>> 1 file changed, 21 insertions(+), 7 deletions(-)
> >>>
> >>> diff --git a/net/colo-compare.c b/net/colo-compare.c index
> >>> 909dd6c6eb..fcccb4c6f6 100644
> >>> --- a/net/colo-compare.c
> >>> +++ b/net/colo-compare.c
> >>> @@ -127,6 +127,17 @@ static int compare_chr_send(CompareState *s,
> >>> uint32_t vnet_hdr_len,
> >>> bool notify_remote_frame);
> >>>
> >>> +static bool packet_matches_str(const char *str,
> >>> + uint8_t *buf,
> >>
> >> You can use 'uint8_t *buf'.
> >
> > ?? that seems to be the same as what is written...
>
> Oops sorry, I copy/pasted and did not noticed I removed the 'const'
> word. So I meant: You can use 'const uint8_t *buf'
OK.
Thanks
Zhang Chen
>
> >>
> >>> + uint32_t packet_len) {
> >>> + if (packet_len != strlen(str)) {
> >>> + return false;
> >>> + }
> >>> +
> >>> + return !memcmp(str, buf, strlen(str));
> >>
> >> If you don't want to use a local variable to hold strlen(str), you
> >> can reuse packet_len since it is the same value:
> >>
> >> return !memcmp(str, buf, packet_len);
> >>
> >> However it makes the review harder, so I'd prefer using a str_len local var.
> >
> > I'm pretty sure the compiler is going to optimise the
> > strlen() away into a compile time constant anyway, so this is somewhat
> > unnecessary micro-optimisation I think.
>
> I was not sure, I'm glad to learn that :)
>
> Thanks,
>
> Phil.
next prev parent reply other threads:[~2019-07-19 1:56 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-18 9:22 [Qemu-devel] [PATCH V3] net/colo-compare.c: Fix memory leak and code style issue Zhang Chen
2019-07-18 10:28 ` Philippe Mathieu-Daudé
2019-07-18 10:37 ` Peter Maydell
2019-07-18 10:53 ` Philippe Mathieu-Daudé
2019-07-19 1:56 ` Zhang, Chen [this message]
2019-07-18 13:42 ` Peter Maydell
2019-07-19 1:54 ` Zhang, Chen
2019-07-21 9:07 ` Zhang, Chen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9CFF81C0F6B98A43A459C9EDAD400D78061D0429@shsmsx102.ccr.corp.intel.com \
--to=chen.zhang@intel.com \
--cc=jasowang@redhat.com \
--cc=lizhijian@cn.fujitsu.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=zhangckid@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).