From e814cd0b9e002e24b25c1990967ab7bc65c64838 Mon Sep 17 00:00:00 2001 From: weiyanhua Date: Thu, 13 Jun 2019 15:05:22 +0800 Subject: add null process for malloc. --- example/ndpi_util.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'example') diff --git a/example/ndpi_util.c b/example/ndpi_util.c index 4b8ffb894..8bf440b59 100644 --- a/example/ndpi_util.c +++ b/example/ndpi_util.c @@ -178,18 +178,21 @@ struct ndpi_workflow* ndpi_workflow_init(const struct ndpi_workflow_prefs * pref set_ndpi_flow_malloc(NULL), set_ndpi_flow_free(NULL); /* TODO: just needed here to init ndpi malloc wrapper */ struct ndpi_detection_module_struct * module = ndpi_init_detection_module(); + if (module == NULL) { + NDPI_LOG(0, NULL, NDPI_LOG_ERROR, "global structure initialization failed\n"); + exit(-1); + } struct ndpi_workflow * workflow = ndpi_calloc(1, sizeof(struct ndpi_workflow)); - + if (workflow == NULL) { + NDPI_LOG(0, NULL, NDPI_LOG_ERROR, "global structure initialization failed\n"); + ndpi_free(module); + exit(-1); + } workflow->pcap_handle = pcap_handle; workflow->prefs = *prefs; workflow->ndpi_struct = module; - if(workflow->ndpi_struct == NULL) { - NDPI_LOG(0, NULL, NDPI_LOG_ERROR, "global structure initialization failed\n"); - exit(-1); - } - ndpi_set_log_level(module, nDPI_LogLevel); if(_debug_protocols != NULL && ! _debug_protocols_ok) { -- cgit v1.2.3