Skip to content

Commit c6cd6b9

Browse files
committed
config: fix a memory leak
1 parent 1f3fbf1 commit c6cd6b9

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

example/ndpiReader.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ static int dpdk_port_id = 0, dpdk_run_capture = 1;
254254
void test_lib(); /* Forward */
255255

256256
extern void ndpi_report_payload_stats(FILE *out);
257+
extern int parse_proto_name_list(char *str, NDPI_PROTOCOL_BITMASK *bitmask, int inverted_logic);
257258

258259
/* ********************************** */
259260

@@ -930,9 +931,9 @@ int __add_cfg(char *proto, char *param, char *value, int dup)
930931
printf("Too many parameter! [num:%d/%d]\n", num_cfgs, MAX_NUM_CFGS);
931932
return -1;
932933
}
933-
cfgs[num_cfgs].proto = ndpi_strdup(proto);
934-
cfgs[num_cfgs].param = ndpi_strdup(param);
935-
cfgs[num_cfgs].value = ndpi_strdup(value);
934+
cfgs[num_cfgs].proto = dup ? ndpi_strdup(proto) : proto;
935+
cfgs[num_cfgs].param = dup ? ndpi_strdup(param) : param;
936+
cfgs[num_cfgs].value = dup ? ndpi_strdup(value) : value;
936937
num_cfgs++;
937938
return 0;
938939
}

fuzz/fuzz_readerutils_workflow.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,14 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
9090
if(w) {
9191
ndpi_set_config(w->ndpi_struct, NULL, "flow.track_payload.enable", "1");
9292
ndpi_set_config(w->ndpi_struct, NULL, "tcp_ack_payload_heuristic.enable", "1");
93-
ndpi_finalize_initialization(w->ndpi_struct);
93+
if(ndpi_finalize_initialization(w->ndpi_struct) != 0) {
9494

95-
header = NULL;
96-
r = pcap_next_ex(pcap_handle, &header, &pkt);
97-
while (r > 0) {
98-
ndpi_workflow_process_packet(w, header, pkt, &flow_risk);
95+
header = NULL;
9996
r = pcap_next_ex(pcap_handle, &header, &pkt);
97+
while (r > 0) {
98+
ndpi_workflow_process_packet(w, header, pkt, &flow_risk);
99+
r = pcap_next_ex(pcap_handle, &header, &pkt);
100+
}
100101
}
101102

102103
ndpi_workflow_free(w);

0 commit comments

Comments
 (0)