[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL V2 30/33] colo-compare: Fix memory leak in packet_enqueue()
From: |
Jason Wang |
Subject: |
[PULL V2 30/33] colo-compare: Fix memory leak in packet_enqueue() |
Date: |
Thu, 18 Jun 2020 21:21:45 +0800 |
From: Derek Su <dereksu@qnap.com>
The patch is to fix the "pkt" memory leak in packet_enqueue().
The allocated "pkt" needs to be freed if the colo compare
primary or secondary queue is too big.
Replace the error_report of full queue with a trace event.
Signed-off-by: Derek Su <dereksu@qnap.com>
Reviewed-by: Zhang Chen <chen.zhang@intel.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Zhang Chen <chen.zhang@intel.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
net/colo-compare.c | 23 +++++++++++++++--------
net/trace-events | 1 +
2 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/net/colo-compare.c b/net/colo-compare.c
index ed1f3d0..f15779d 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -146,6 +146,10 @@ enum {
SECONDARY_IN,
};
+static const char *colo_mode[] = {
+ [PRIMARY_IN] = "primary",
+ [SECONDARY_IN] = "secondary",
+};
static int compare_chr_send(CompareState *s,
uint8_t *buf,
@@ -242,6 +246,7 @@ static int packet_enqueue(CompareState *s, int mode,
Connection **con)
ConnectionKey key;
Packet *pkt = NULL;
Connection *conn;
+ int ret;
if (mode == PRIMARY_IN) {
pkt = packet_new(s->pri_rs.buf,
@@ -270,16 +275,18 @@ static int packet_enqueue(CompareState *s, int mode,
Connection **con)
}
if (mode == PRIMARY_IN) {
- if (!colo_insert_packet(&conn->primary_list, pkt, &conn->pack)) {
- error_report("colo compare primary queue size too big,"
- "drop packet");
- }
+ ret = colo_insert_packet(&conn->primary_list, pkt, &conn->pack);
} else {
- if (!colo_insert_packet(&conn->secondary_list, pkt, &conn->sack)) {
- error_report("colo compare secondary queue size too big,"
- "drop packet");
- }
+ ret = colo_insert_packet(&conn->secondary_list, pkt, &conn->sack);
}
+
+ if (!ret) {
+ trace_colo_compare_drop_packet(colo_mode[mode],
+ "queue size too big, drop packet");
+ packet_destroy(pkt, NULL);
+ pkt = NULL;
+ }
+
*con = conn;
return 0;
diff --git a/net/trace-events b/net/trace-events
index 02c13fd..fa49c71 100644
--- a/net/trace-events
+++ b/net/trace-events
@@ -12,6 +12,7 @@ colo_proxy_main(const char *chr) ": %s"
# colo-compare.c
colo_compare_main(const char *chr) ": %s"
+colo_compare_drop_packet(const char *queue, const char *chr) ": %s: %s"
colo_compare_udp_miscompare(const char *sta, int size) ": %s = %d"
colo_compare_icmp_miscompare(const char *sta, int size) ": %s = %d"
colo_compare_ip_info(int psize, const char *sta, const char *stb, int ssize,
const char *stc, const char *std) "ppkt size = %d, ip_src = %s, ip_dst = %s,
spkt size = %d, ip_src = %s, ip_dst = %s"
--
2.5.0
- [PULL V2 23/33] net: use peer when purging queue in qemu_flush_or_purge_queue_packets(), (continued)
- [PULL V2 23/33] net: use peer when purging queue in qemu_flush_or_purge_queue_packets(), Jason Wang, 2020/06/18
- [PULL V2 24/33] net/colo-compare.c: Create event_bh with the right AioContext, Jason Wang, 2020/06/18
- [PULL V2 25/33] chardev/char.c: Use qemu_co_sleep_ns if in coroutine, Jason Wang, 2020/06/18
- [PULL V2 26/33] net/colo-compare.c: Fix deadlock in compare_chr_send, Jason Wang, 2020/06/18
- [PULL V2 27/33] net/colo-compare.c: Only hexdump packets if tracing is enabled, Jason Wang, 2020/06/18
- [PULL V2 28/33] net/colo-compare.c: Check that colo-compare is active, Jason Wang, 2020/06/18
- [PULL V2 29/33] net/colo-compare.c: Correct ordering in complete and finalize, Jason Wang, 2020/06/18
- [PULL V2 31/33] hw/net/e1000e: Do not abort() on invalid PSRCTL register value, Jason Wang, 2020/06/18
- [PULL V2 32/33] net: Drop the legacy "name" parameter from the -net option, Jason Wang, 2020/06/18
- [PULL V2 33/33] net: Drop the NetLegacy structure, always use Netdev instead, Jason Wang, 2020/06/18
- [PULL V2 30/33] colo-compare: Fix memory leak in packet_enqueue(),
Jason Wang <=
- Re: [PULL V2 00/33] Net patches, no-reply, 2020/06/18
- Re: [PULL V2 00/33] Net patches, Peter Maydell, 2020/06/19