for (i = 0; i < no_of_detect_tvs; i++) {
int break_out = 0;
- while (new_det_ctx[i]->so_far_used_by_detect != 1) {
+ while (SC_ATOMIC_GET(new_det_ctx[i]->so_far_used_by_detect) != 1) {
if (suricata_ctl_flags != 0) {
break_out = 1;
break;
SCLogDebug("new_det_ctx - %p used by detect engine", new_det_ctx[i]);
}
+ /* this is to make sure that if someone initiated shutdown during a live
+ * rule swap, the live rule swap won't clean up the old det_ctx and
+ * de_ctx, till all detect threads have stopped working and sitting
+ * silently after setting RUNNING_DONE flag and while waiting for
+ * THV_DEINIT flag */
if (i != no_of_detect_tvs) {
ThreadVars *tv = tv_root[TVT_PPT];
while (tv) {
return TM_ECODE_FAILED;
}
+ SC_ATOMIC_INIT(det_ctx->so_far_used_by_detect);
+
*data = (void *)det_ctx;
return TM_ECODE_OK;
return TM_ECODE_FAILED;
}
+ SC_ATOMIC_INIT(det_ctx->so_far_used_by_detect);
+
*data = (void *)det_ctx;
return TM_ECODE_OK;
goto error;
}
- if (det_ctx->so_far_used_by_detect == 0) {
- det_ctx->so_far_used_by_detect = 1;
+ if (SC_ATOMIC_GET(det_ctx->so_far_used_by_detect) == 0) {
+ SC_ATOMIC_SET(det_ctx->so_far_used_by_detect, 1);
SCLogDebug("Detect Engine using new det_ctx - %p and de_ctx - %p",
det_ctx, de_ctx);
}
/** ID of the transaction currently being inspected. */
uint16_t tx_id;
- uint16_t so_far_used_by_detect;
+ SC_ATOMIC_DECLARE(uint16_t, so_far_used_by_detect);
/* holds the current recursion depth on content inspection */
int inspection_recursion_counter;
#include "util-atomic.h"
#include "util-unittest.h"
+#ifdef UNITTESTS
+
static int SCAtomicTest01(void)
{
int result = 0;
return result;
}
+#endif /* UNITTESTS */
+
void SCAtomicRegisterTests(void)
{
+#ifdef UNITTESTS
UtRegisterTest("SCAtomicTest01", SCAtomicTest01, 1);
+#endif
return;
}
fd = NULL;
}
- regex = NULL;
- regex_study = NULL;
+ if (regex != NULL) {
+ pcre_free(regex);
+ regex = NULL;
+ }
+ if (regex_study != NULL) {
+ //pcre_free_study(regex_study);
+ regex_study = NULL;
+ }
return -1;
}
fclose(fd);
default_file_path = SC_CLASS_CONF_DEF_CONF_FILEPATH;
fd = NULL;
- regex = NULL;
- regex_study = NULL;
+ if (regex != NULL) {
+ pcre_free(regex_study);
+ regex = NULL;
+ }
+ if (regex_study != NULL) {
+ //pcre_free_study(regex_study);
+ regex_study = NULL;
+ }
return;
}
SCClassConfClasstype *ct_info = SCClassConfAllocClasstype(0, ct_name, NULL,
0);
if (ct_info == NULL)
- exit(EXIT_FAILURE);
+ return NULL;
SCClassConfClasstype *lookup_ct_info = HashTableLookup(de_ctx->class_conf_ht,
ct_info, 0);
fd = NULL;
}
- regex = NULL;
- regex_study = NULL;
+ if (regex != NULL) {
+ pcre_free(regex);
+ regex = NULL;
+ }
+ if (regex_study != NULL) {
+ //pcre_free_study(regex_study);
+ regex_study = NULL;
+ }
return -1;
}
fclose(fd);
file_path = SC_RCONF_DEFAULT_FILE_PATH;
fd = NULL;
- regex = NULL;
- regex_study = NULL;
+
+ if (regex != NULL) {
+ pcre_free(regex);
+ regex = NULL;
+ }
+ if (regex_study != NULL) {
+ //pcre_free_study(regex_study);
+ regex_study = NULL;
+ }
return;
}
* \author Anoop Saldanha <anoopsaldanha@gmail.com>
*/
-#ifndef __UTIL_STRING_H__
-#define __UTIL_STRING_H__
+#ifndef __UTIL_SIGNAL_H__
+#define __UTIL_SIGNAL_H__
int UtilSignalBlock(int);
void UtilSignalHandlerSetup(int, void (*handler)());;
int UtilSignalIsHandler(int sig, void (*handler)());
-#endif /* __UTIL_STRING_H__ */
+#endif /* __UTIL_SIGNAL_H__ */
if (fd != NULL)
fclose(fd);
- regex_base = NULL;
- regex_base_study = NULL;
+ if (regex_base != NULL) {
+ pcre_free(regex_base);
+ regex_base = NULL;
+ }
+ if (regex_base_study != NULL) {
+ //pcre_free_study(regex_base_study);
+ regex_base_study = NULL;
+ }
- regex_threshold = NULL;
- regex_threshold_study = NULL;
+ if (regex_threshold != NULL) {
+ pcre_free(regex_threshold);
+ regex_threshold = NULL;
+ }
+ if (regex_threshold_study != NULL) {
+ //pcre_free_study(regex_threshold_study);
+ regex_threshold_study = NULL;
+ }
- regex_rate = NULL;
- regex_rate_study = NULL;
+ if (regex_rate != NULL) {
+ pcre_free(regex_rate);
+ regex_rate = NULL;
+ }
+ if (regex_rate_study != NULL) {
+ //pcre_free_study(regex_rate_study);
+ regex_rate_study = NULL;
+ }
- regex_suppress = NULL;
- regex_suppress_study = NULL;
+ if (regex_suppress != NULL) {
+ pcre_free(regex_suppress);
+ regex_suppress = NULL;
+ }
+ if (regex_suppress_study != NULL) {
+ //pcre_free_study(regex_suppress_study);
+ regex_suppress_study = NULL;
+ }
return;
}