From a17c1d32efb9e31054c3f2158eb087253e4f242f Mon Sep 17 00:00:00 2001 From: Alina Lenk Date: Mon, 29 Apr 2024 23:39:01 +0200 Subject: [PATCH] json protocol: free json object when discarding info packet See RM #511 Signed-off-by: Alina Lenk --- common/generate_packets.py | 2 +- common/networking/packets.h | 3 +++ common/networking/packets_json.h | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/common/generate_packets.py b/common/generate_packets.py index 3eb783bc86..03723ef16a 100755 --- a/common/generate_packets.py +++ b/common/generate_packets.py @@ -2260,7 +2260,7 @@ if (different == 0) {{ {fl}\ {s}\ {before_return}\ - return 0; + SEND_PACKET_DISCARD(); }} """.format(fl = fl, s = s, before_return = before_return) diff --git a/common/networking/packets.h b/common/networking/packets.h index d756701cbd..5f1028ad7b 100644 --- a/common/networking/packets.h +++ b/common/networking/packets.h @@ -143,6 +143,9 @@ void packets_deinit(void); return send_packet_data(pc, buffer, size, packet_type); \ } +#define SEND_PACKET_DISCARD() \ + return 0 + #define RECEIVE_PACKET_START(packet_type, result) \ struct data_in din; \ struct packet_type packet_buf, *result = &packet_buf; \ diff --git a/common/networking/packets_json.h b/common/networking/packets_json.h index c3fcd6ae39..4436a6fe25 100644 --- a/common/networking/packets_json.h +++ b/common/networking/packets_json.h @@ -67,6 +67,14 @@ void *get_packet_from_connection_json(struct connection *pc, return send_packet_data(pc, buffer, size, packet_type); \ } +#define SEND_PACKET_DISCARD() \ + { \ + if (pc->json_mode) { \ + json_decref(dout.json); \ + } \ + return 0; \ + } + #define RECEIVE_PACKET_START(packet_type, result) \ struct packet_type packet_buf, *result = &packet_buf; \ struct data_in din; \ -- 2.34.1