Skip to content

Commit bdadbb0

Browse files
derekbitjasowang
authored andcommitted
colo-compare: Fix memory leak in packet_enqueue()
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 <[email protected]> Reviewed-by: Zhang Chen <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Signed-off-by: Zhang Chen <[email protected]> Signed-off-by: Jason Wang <[email protected]>
1 parent 5bd57eb commit bdadbb0

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

net/colo-compare.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ enum {
146146
SECONDARY_IN,
147147
};
148148

149+
static const char *colo_mode[] = {
150+
[PRIMARY_IN] = "primary",
151+
[SECONDARY_IN] = "secondary",
152+
};
149153

150154
static int compare_chr_send(CompareState *s,
151155
uint8_t *buf,
@@ -242,6 +246,7 @@ static int packet_enqueue(CompareState *s, int mode, Connection **con)
242246
ConnectionKey key;
243247
Packet *pkt = NULL;
244248
Connection *conn;
249+
int ret;
245250

246251
if (mode == PRIMARY_IN) {
247252
pkt = packet_new(s->pri_rs.buf,
@@ -270,16 +275,18 @@ static int packet_enqueue(CompareState *s, int mode, Connection **con)
270275
}
271276

272277
if (mode == PRIMARY_IN) {
273-
if (!colo_insert_packet(&conn->primary_list, pkt, &conn->pack)) {
274-
error_report("colo compare primary queue size too big,"
275-
"drop packet");
276-
}
278+
ret = colo_insert_packet(&conn->primary_list, pkt, &conn->pack);
277279
} else {
278-
if (!colo_insert_packet(&conn->secondary_list, pkt, &conn->sack)) {
279-
error_report("colo compare secondary queue size too big,"
280-
"drop packet");
281-
}
280+
ret = colo_insert_packet(&conn->secondary_list, pkt, &conn->sack);
282281
}
282+
283+
if (!ret) {
284+
trace_colo_compare_drop_packet(colo_mode[mode],
285+
"queue size too big, drop packet");
286+
packet_destroy(pkt, NULL);
287+
pkt = NULL;
288+
}
289+
283290
*con = conn;
284291

285292
return 0;

net/trace-events

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ colo_proxy_main(const char *chr) ": %s"
1212

1313
# colo-compare.c
1414
colo_compare_main(const char *chr) ": %s"
15+
colo_compare_drop_packet(const char *queue, const char *chr) ": %s: %s"
1516
colo_compare_udp_miscompare(const char *sta, int size) ": %s = %d"
1617
colo_compare_icmp_miscompare(const char *sta, int size) ": %s = %d"
1718
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"

0 commit comments

Comments
 (0)