From: Victor Julien Date: Wed, 8 Apr 2015 13:15:29 +0000 (+0200) Subject: classification: cleanups X-Git-Tag: suricata-2.1beta4~44 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cc38df80747d4789282ce2c5d10168df4b403712;p=thirdparty%2Fsuricata.git classification: cleanups Reduce hash table size as regular classification files are usually below 100 in size. It's not performance critical anyway. Convert pcre_get_substring calls to pcre_copy_substring. --- diff --git a/src/util-classification-config.c b/src/util-classification-config.c index db79b7a213..51d18fdb2e 100644 --- a/src/util-classification-config.c +++ b/src/util-classification-config.c @@ -81,7 +81,7 @@ int SCClassConfInitContextAndLocalResources(DetectEngineCtx *de_ctx) int opts = 0; /* init the hash table to be used by the classification config Classtypes */ - de_ctx->class_conf_ht = HashTableInit(4096, SCClassConfClasstypeHashFunc, + de_ctx->class_conf_ht = HashTableInit(128, SCClassConfClasstypeHashFunc, SCClassConfClasstypeHashCompareFunc, SCClassConfClasstypeHashFree); if (de_ctx->class_conf_ht == NULL) { @@ -235,9 +235,9 @@ static char *SCClassConfStringToLowercase(const char *str) */ int SCClassConfAddClasstype(char *rawstr, uint8_t index, DetectEngineCtx *de_ctx) { - const char *ct_name = NULL; - const char *ct_desc = NULL; - const char *ct_priority_str = NULL; + char ct_name[64]; + char ct_desc[512]; + char ct_priority_str[16]; int ct_priority = 0; uint8_t ct_id = index; @@ -256,23 +256,23 @@ int SCClassConfAddClasstype(char *rawstr, uint8_t index, DetectEngineCtx *de_ctx } /* retrieve the classtype name */ - ret = pcre_get_substring((char *)rawstr, ov, 30, 1, &ct_name); + ret = pcre_copy_substring((char *)rawstr, ov, 30, 1, ct_name, sizeof(ct_name)); if (ret < 0) { - SCLogInfo("pcre_get_substring() failed"); + SCLogInfo("pcre_copy_substring() failed"); goto error; } /* retrieve the classtype description */ - ret = pcre_get_substring((char *)rawstr, ov, 30, 2, &ct_desc); + ret = pcre_copy_substring((char *)rawstr, ov, 30, 2, ct_desc, sizeof(ct_desc)); if (ret < 0) { - SCLogInfo("pcre_get_substring() failed"); + SCLogInfo("pcre_copy_substring() failed"); goto error; } /* retrieve the classtype priority */ - ret = pcre_get_substring((char *)rawstr, ov, 30, 3, &ct_priority_str); + ret = pcre_copy_substring((char *)rawstr, ov, 30, 3, ct_priority_str, sizeof(ct_priority_str)); if (ret < 0) { - SCLogInfo("pcre_get_substring() failed"); + SCLogInfo("pcre_copy_substring() failed"); goto error; } if (ct_priority_str == NULL) { @@ -299,16 +299,9 @@ int SCClassConfAddClasstype(char *rawstr, uint8_t index, DetectEngineCtx *de_ctx SCFree(ct_new); } - if (ct_name) SCFree((char *)ct_name); - if (ct_desc) SCFree((char *)ct_desc); - if (ct_priority_str) SCFree((char *)ct_priority_str); return 0; error: - if (ct_name) SCFree((char *)ct_name); - if (ct_desc) SCFree((char *)ct_desc); - if (ct_priority_str) SCFree((char *)ct_priority_str); - return -1; }