Skip to content

Commit

Permalink
config: fix a memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanNardi committed Dec 17, 2023
1 parent 1f3fbf1 commit c6cd6b9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
7 changes: 4 additions & 3 deletions example/ndpiReader.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ static int dpdk_port_id = 0, dpdk_run_capture = 1;
void test_lib(); /* Forward */

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

/* ********************************** */

Expand Down Expand Up @@ -930,9 +931,9 @@ int __add_cfg(char *proto, char *param, char *value, int dup)
printf("Too many parameter! [num:%d/%d]\n", num_cfgs, MAX_NUM_CFGS);
return -1;
}
cfgs[num_cfgs].proto = ndpi_strdup(proto);
cfgs[num_cfgs].param = ndpi_strdup(param);
cfgs[num_cfgs].value = ndpi_strdup(value);
cfgs[num_cfgs].proto = dup ? ndpi_strdup(proto) : proto;
cfgs[num_cfgs].param = dup ? ndpi_strdup(param) : param;
cfgs[num_cfgs].value = dup ? ndpi_strdup(value) : value;
num_cfgs++;
return 0;
}
Expand Down
11 changes: 6 additions & 5 deletions fuzz/fuzz_readerutils_workflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if(w) {
ndpi_set_config(w->ndpi_struct, NULL, "flow.track_payload.enable", "1");
ndpi_set_config(w->ndpi_struct, NULL, "tcp_ack_payload_heuristic.enable", "1");
ndpi_finalize_initialization(w->ndpi_struct);
if(ndpi_finalize_initialization(w->ndpi_struct) != 0) {

header = NULL;
r = pcap_next_ex(pcap_handle, &header, &pkt);
while (r > 0) {
ndpi_workflow_process_packet(w, header, pkt, &flow_risk);
header = NULL;
r = pcap_next_ex(pcap_handle, &header, &pkt);
while (r > 0) {
ndpi_workflow_process_packet(w, header, pkt, &flow_risk);
r = pcap_next_ex(pcap_handle, &header, &pkt);
}
}

ndpi_workflow_free(w);
Expand Down

0 comments on commit c6cd6b9

Please sign in to comment.