void session_destroy(void) { struct session_table *tables[] = { &session_table_udp, &session_table_tcp, &session_table_icmp }; int i; log_debug("Emptying the session tables..."); /* * The values need to be released only in one of the trees * because both trees point to the same values. */ for (i = 0; i < ARRAY_SIZE(tables); i++) rbtree_clear(&tables[i]->tree6, session_destroy_aux); kmem_cache_destroy(entry_cache); }
/* * Checks for infinite loops. Every parsing state must either consume * some data or change the state to one that hasn't been used at this * position. As there are a finite number of states this ensures that * parsing will stop at some point or be detected by this function. */ static bool loop_check(JSONRD_T *jsonrd, PS_EN prior_state, int consumed) { RBTREE_T *prior_states; PS_EN new_state; bool is_new_state; prior_states = jsonrd->prior_states; if (consumed == 0) { new_state = jsonrd->state; if (rbtree_size(prior_states) == 0) { if (prior_state == new_state) return true; rbtree_put(prior_states, &prior_state, NULL); rbtree_put(prior_states, &new_state, NULL); } else { rbtree_lookup(prior_states, &new_state, true, &is_new_state); if (!is_new_state) return true; } } else { rbtree_clear(prior_states); } return false; }
/***************************************************************************** * Updates the JSON reader with a chunk of text to parse. ****************************************************************************/ void jsonrd_update(JSONRD_T *jsonrd, const char *chunk, size_t size, bool end) { assert(jsonrd != NULL); assert(size >= 0); int offset, consumed; PS_EN prior_state; rbtree_clear(jsonrd->prior_states); if (size > 0) { assert(chunk != NULL); offset = 0; while (offset < size) { prior_state = jsonrd->state; consumed = dispatch(jsonrd, chunk+offset, size - offset); offset += consumed; // check for parser problems if (loop_check(jsonrd, prior_state, consumed)) die("Infinite loop detected."); assert(offset <= size); } } if (end) { if (jsonrd->state != PS_FIND_LANDMARK && jsonrd->state != PS_ERROR) { error(jsonrd, "Missing end of data"); } } }