From: Jason Wang <jasowang@redhat.com>
To: qemu-devel@nongnu.org, peter.maydell@linaro.org
Cc: Zhang Chen <chen.zhang@intel.com>, Jason Wang <jasowang@redhat.com>
Subject: [Qemu-devel] [PULL 5/5] net/colo-compare.c: Fix memory leak and code style issue.
Date: Mon, 29 Jul 2019 16:33:46 +0800 [thread overview]
Message-ID: <1564389226-4489-6-git-send-email-jasowang@redhat.com> (raw)
In-Reply-To: <1564389226-4489-1-git-send-email-jasowang@redhat.com>
From: Zhang Chen <chen.zhang@intel.com>
This patch to fix the origin "char *data" memory leak, code style issue
and add necessary check here.
Reported-by: Coverity (CID 1402785)
Signed-off-by: Zhang Chen <chen.zhang@intel.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
net/colo-compare.c | 27 ++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)
diff --git a/net/colo-compare.c b/net/colo-compare.c
index 909dd6c..7489840 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,
+ const uint8_t *buf,
+ uint32_t packet_len)
+{
+ if (packet_len != strlen(str)) {
+ return false;
+ }
+
+ return !memcmp(str, buf, strlen(str));
+}
+
static void notify_remote_frame(CompareState *s)
{
char msg[] = "DO_CHECKPOINT";
@@ -1008,21 +1019,23 @@ static void compare_notify_rs_finalize(SocketReadState *notify_rs)
{
CompareState *s = container_of(notify_rs, CompareState, notify_rs);
- /* Get Xen colo-frame's notify and handle the message */
- char *data = g_memdup(notify_rs->buf, notify_rs->packet_len);
- char msg[] = "COLO_COMPARE_GET_XEN_INIT";
+ const char msg[] = "COLO_COMPARE_GET_XEN_INIT";
int ret;
- if (!strcmp(data, "COLO_USERSPACE_PROXY_INIT")) {
+ if (packet_matches_str("COLO_USERSPACE_PROXY_INIT",
+ notify_rs->buf,
+ notify_rs->packet_len)) {
ret = compare_chr_send(s, (uint8_t *)msg, strlen(msg), 0, true);
if (ret < 0) {
error_report("Notify Xen COLO-frame INIT failed");
}
- }
-
- if (!strcmp(data, "COLO_CHECKPOINT")) {
+ } else if (packet_matches_str("COLO_CHECKPOINT",
+ notify_rs->buf,
+ notify_rs->packet_len)) {
/* colo-compare do checkpoint, flush pri packet and remove sec packet */
g_queue_foreach(&s->conn_list, colo_flush_packets, s);
+ } else {
+ error_report("COLO compare got unsupported instruction");
}
}
--
2.5.0
next prev parent reply other threads:[~2019-07-29 8:34 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-29 8:33 [Qemu-devel] [PULL 0/5] Net patches Jason Wang
2019-07-29 8:33 ` [Qemu-devel] [PULL 1/5] e1000: don't raise interrupt in pre_save() Jason Wang
2019-07-29 8:33 ` [Qemu-devel] [PULL 2/5] qemu-bridge-helper: restrict interface name to IFNAMSIZ Jason Wang
2019-07-29 8:33 ` [Qemu-devel] [PULL 3/5] qemu-bridge-helper: move repeating code in parse_acl_file Jason Wang
2019-07-29 8:33 ` [Qemu-devel] [PULL 4/5] net: tap: replace snprintf with g_strdup_printf calls Jason Wang
2019-07-29 8:33 ` Jason Wang [this message]
2019-07-29 11:47 ` [Qemu-devel] [PULL 0/5] Net patches Peter Maydell
2019-07-29 12:50 ` Jason Wang
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=1564389226-4489-6-git-send-email-jasowang@redhat.com \
--to=jasowang@redhat.com \
--cc=chen.zhang@intel.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/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).