From cb36dee47783b2a7c91fd0b0138dee8bd37354b9 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Wed, 18 Jan 2017 15:13:40 +0100 Subject: [PATCH] hyperscan: fix minor coverity issue in error path *** CID 1398951: API usage errors (LOCK) /src/util-mpm-hs.c: 722 in SCHSPreparePatterns() 716 SCMutexUnlock(&g_db_table_mutex); 717 718 SCHSFreeCompileData(cd); 719 return 0; 720 721 error: >>> CID 1398951: API usage errors (LOCK) >>> "pthread_mutex_unlock" unlocks "g_db_table_mutex" while it is unlocked. 722 SCMutexUnlock(&g_db_table_mutex); 723 if (pd) { 724 PatternDatabaseFree(pd); 725 } 726 if (cd) { --- src/util-mpm-hs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/util-mpm-hs.c b/src/util-mpm-hs.c index 61224d743c..2b59eeaff8 100644 --- a/src/util-mpm-hs.c +++ b/src/util-mpm-hs.c @@ -657,6 +657,7 @@ int SCHSPreparePatterns(MpmCtx *mpm_ctx) if (p->flags & (MPM_PATTERN_FLAG_OFFSET | MPM_PATTERN_FLAG_DEPTH)) { cd->ext[i] = SCMalloc(sizeof(hs_expr_ext_t)); if (cd->ext[i] == NULL) { + SCMutexUnlock(&g_db_table_mutex); goto error; } memset(cd->ext[i], 0, sizeof(hs_expr_ext_t)); @@ -685,6 +686,7 @@ int SCHSPreparePatterns(MpmCtx *mpm_ctx) SCLogError(SC_ERR_FATAL, "compile error: %s", compile_err->message); } hs_free_compile_error(compile_err); + SCMutexUnlock(&g_db_table_mutex); goto error; } @@ -695,12 +697,14 @@ int SCHSPreparePatterns(MpmCtx *mpm_ctx) SCMutexUnlock(&g_scratch_proto_mutex); if (err != HS_SUCCESS) { SCLogError(SC_ERR_FATAL, "failed to allocate scratch"); + SCMutexUnlock(&g_db_table_mutex); goto error; } err = hs_database_size(pd->hs_db, &ctx->hs_db_size); if (err != HS_SUCCESS) { SCLogError(SC_ERR_FATAL, "failed to query database size"); + SCMutexUnlock(&g_db_table_mutex); goto error; } @@ -719,7 +723,6 @@ int SCHSPreparePatterns(MpmCtx *mpm_ctx) return 0; error: - SCMutexUnlock(&g_db_table_mutex); if (pd) { PatternDatabaseFree(pd); }