Project

General

Profile

Bug #186 » 0001-Bug-186-fix.-It-seems-that-on-Mac-OS-X-we-where-reac.patch

Bug #186 fix. It seems that on Mac OS X we where reaching the max stack frame. Now states are free() by iterating avoiding recursive calls. Moved the de_state mutex to flow to avoid destroying it while destroying de_state - Pablo Rincon, 06/22/2010 07:23 AM

View differences:

src/detect-engine-state.c
}
memset(d, 0x00, sizeof(DetectEngineState));
SCMutexInit(&d->m, NULL);
SCReturnPtr(d, "DetectEngineState");
}
/**
* \brief Free a DetectEngineState object
* You must lock the flow mutex for de_state
* (f->de_state_m)
* \param state DetectEngineState object to free
*/
void DetectEngineStateFree(DetectEngineState *state) {
DeStateStore *iter = NULL;
DeStateStore *aux = NULL;
if (state == NULL)
return;
if (state->head != NULL) {
DeStateStoreFree(state->head);
iter = state->head;
while (iter != NULL) {
aux = iter;
iter = iter->next;
SCFree(aux);
}
SCMutexDestroy(&state->m);
state->head = NULL;
state->tail = NULL;
state->cnt = 0;
SCFree(state);
}
......
void DetectEngineStateReset(DetectEngineState *state) {
SCEnter();
if (state == NULL) {
SCReturn;
}
DeStateStore *iter = NULL;
DeStateStore *aux = NULL;
SCMutexLock(&state->m);
if (state == NULL)
return;
if (state->head != NULL) {
DeStateStoreFree(state->head);
iter = state->head;
while (iter != NULL) {
aux = iter;
iter = iter->next;
SCFree(aux);
}
state->head = NULL;
state->tail = NULL;
state->cnt = 0;
SCMutexUnlock(&state->m);
SCReturn;
}
......
SCMutexUnlock(&f->m);
if (f->de_state != NULL) {
SCMutexLock(&f->de_state->m);
SCMutexLock(&f->de_state_m);
DeStateSignatureAppend(f->de_state, s, sm, umatch, dmatch);
SCMutexUnlock(&f->de_state->m);
SCMutexUnlock(&f->de_state_m);
}
SCReturnInt(r);
......
return 0;
}
SCMutexLock(&f->de_state->m);
SCMutexLock(&f->de_state_m);
if (f->de_state->cnt == 0)
goto end;
......
}
end:
SCMutexUnlock(&f->de_state->m);
SCMutexUnlock(&f->de_state_m);
SCReturnInt(0);
}
......
* to the previous transaction */
SCMutexLock(&f->m);
if (f->de_state != NULL) {
SCMutexLock(&f->de_state->m);
DetectEngineStateReset(f->de_state);
SCMutexUnlock(&f->de_state->m);
SCMutexLock(&f->de_state_m);
if (f->de_state != NULL) {
DetectEngineStateReset(f->de_state);
}
SCMutexUnlock(&f->de_state_m);
}
SCMutexUnlock(&f->m);
src/detect-engine-state.h
DeStateStore *head; /**< signature state storage */
DeStateStore *tail; /**< tail item of the storage list */
SigIntId cnt; /**< number of sigs in the storage */
SCMutex m; /**< lock for the de_state object */
uint8_t use_cnt; /**< number of threads accesing */
} DetectEngineState;
void DeStateRegisterTests(void);
src/detect.c
/* grab the protocol state we will detect on */
if (p->flow != NULL) {
/* Sanity check of use_cnt */
FlowIncrUsecnt(p->flow);
SCMutexLock(&p->flow->m);
......
int de_state_status = DeStateUpdateInspectTransactionId(p->flow,
(flags & STREAM_TOSERVER) ? STREAM_TOSERVER : STREAM_TOCLIENT);
SCLogDebug("de_state_status %d", de_state_status);
if (de_state_status == 2) {
BUG_ON(SC_ATOMIC_GET(p->flow->use_cnt) < 2);
SCMutexLock(&p->flow->de_state_m);
DetectEngineStateReset(p->flow->de_state);
SCMutexUnlock(&p->flow->de_state_m);
}
}
src/flow-util.c
FLOW_INITIALIZE(f);
SCMutexInit(&f->de_state_m, NULL);
f->alproto = 0;
f->aldata = NULL;
f->alflags = FLOW_AL_PROTO_UNKNOWN;
src/flow-util.h
(f)->flowvar = NULL; \
(f)->protoctx = NULL; \
SC_ATOMIC_RESET((f)->use_cnt); \
DetectEngineStateFree((f)->de_state); \
SCMutexLock(&(f)->de_state_m); \
if ((f)->de_state != NULL) { \
DetectEngineStateFree((f)->de_state); \
} \
SCMutexUnlock(&(f)->de_state_m); \
(f)->de_state = NULL; \
(f)->sgh_toserver = NULL; \
(f)->sgh_toclient = NULL; \
......
(f)->flowvar = NULL; \
(f)->protoctx = NULL; \
SC_ATOMIC_DESTROY((f)->use_cnt); \
DetectEngineStateFree((f)->de_state); \
SCMutexLock(&(f)->de_state_m); \
if ((f)->de_state != NULL) { \
DetectEngineStateFree((f)->de_state); \
} \
SCMutexUnlock(&(f)->de_state_m); \
(f)->de_state = NULL; \
SCMutexDestroy(&(f)->de_state_m); \
AppLayerParserCleanupState(f); \
FlowL7DataPtrFree(f); \
SCFree((f)->aldata); \
src/flow.h
/** detection engine state */
struct DetectEngineState_ *de_state;
SCMutex de_state_m; /**< mutex lock for the de_state object */
/** toclient sgh for this flow. Only use when FLOW_SGH_TOCLIENT flow flag
* has been set. */
(1-1/2)