Пример #1
0
/** Free the memory allocated to an attack vector object
 *
 * @param av        The attack vector to be freed
 */
static void attack_vector_free(attack_vector_t *av)
{
  if(av == NULL)
    {
      return;
    }

  if(av->initial_packet != NULL)
    {
      /*trace_destroy_packet(av->initial_packet);*/
      free(av->initial_packet);
    }

  if(av->attack_ip_hash != NULL)
    {
      kh_destroy(32xx, av->attack_ip_hash);
    }
  if(av->attack_port_hash != NULL)
    {
      kh_destroy(32xx, av->attack_port_hash);
    }
  if(av->target_port_hash != NULL)
    {
      kh_destroy(32xx, av->target_port_hash);
    }

  free(av);
  return;
}
Пример #2
0
void SR_BamInStreamFree(SR_BamInStream* pBamInStream)
{
    if (pBamInStream != NULL)
    {
        kh_destroy(queryName, pBamInStream->pNameHashes[PREV_BIN]);
        kh_destroy(queryName, pBamInStream->pNameHashes[CURR_BIN]);

        if (pBamInStream->pRetLists != NULL)
	  free(pBamInStream->pRetLists);
        if (pBamInStream->pAlgnTypes != NULL)
	  free(pBamInStream->pAlgnTypes);
        SR_BamMemPoolFree(pBamInStream->pMemPool);

        bam_close(pBamInStream->fpBamInput);
        bam_index_destroy(pBamInStream->pBamIndex);

	if (pBamInStream->pBamIterator != NULL) {
	  bam_iter_destroy(*(pBamInStream->pBamIterator));
	  free(pBamInStream->pBamIterator);
	  pBamInStream->pBamIterator = NULL;
	}

        free(pBamInStream);
    }
}
Пример #3
0
static void
writer_control_destroy(struct writer_control *p)
{
  pic_state *pic = p->pic;
  kh_destroy(l, &p->labels);
  kh_destroy(v, &p->visited);
}
Пример #4
0
/* destroy the memory allocated for bgpstream filter */
void bgpstream_filter_mgr_destroy(bgpstream_filter_mgr_t *bs_filter_mgr)
{
  bgpstream_debug("\tBSF_MGR:: destroy start");
  if (bs_filter_mgr == NULL) {
    return; // nothing to destroy
  }
  // destroying filters
  bgpstream_interval_filter_t *tif;
  khiter_t k;
  // projects
  if (bs_filter_mgr->projects != NULL) {
    bgpstream_str_set_destroy(bs_filter_mgr->projects);
  }
  // collectors
  if (bs_filter_mgr->collectors != NULL) {
    bgpstream_str_set_destroy(bs_filter_mgr->collectors);
  }
  // bgp_types
  if (bs_filter_mgr->bgp_types != NULL) {
    bgpstream_str_set_destroy(bs_filter_mgr->bgp_types);
  }
  // peer asns
  if (bs_filter_mgr->peer_asns != NULL) {
    bgpstream_id_set_destroy(bs_filter_mgr->peer_asns);
  }
  // aspath expressions
  if (bs_filter_mgr->aspath_exprs != NULL) {
    bgpstream_str_set_destroy(bs_filter_mgr->aspath_exprs);
  }
  // prefixes
  if (bs_filter_mgr->prefixes != NULL) {
    bgpstream_patricia_tree_destroy(bs_filter_mgr->prefixes);
  }
  // communities
  if (bs_filter_mgr->communities != NULL) {
    kh_destroy(bgpstream_community_filter, bs_filter_mgr->communities);
  }
  // time_intervals
  tif = NULL;
  while (bs_filter_mgr->time_intervals != NULL) {
    tif = bs_filter_mgr->time_intervals;
    bs_filter_mgr->time_intervals = bs_filter_mgr->time_intervals->next;
    free(tif);
  }
  // rib/update frequency
  if (bs_filter_mgr->last_processed_ts != NULL) {
    for (k = kh_begin(bs_filter_mgr->last_processed_ts);
         k != kh_end(bs_filter_mgr->last_processed_ts); ++k) {
      if (kh_exist(bs_filter_mgr->last_processed_ts, k)) {
        free(kh_key(bs_filter_mgr->last_processed_ts, k));
      }
    }
    kh_destroy(collector_ts, bs_filter_mgr->last_processed_ts);
  }
  // free the mgr structure
  free(bs_filter_mgr);
  bs_filter_mgr = NULL;
  bgpstream_debug("\tBSF_MGR:: destroy end");
}
Пример #5
0
/** Implements the close_output function of the plugin API */
int bgpcorsaro_pfxmonitor_close_output(bgpcorsaro_t *bgpcorsaro)
{
  int i;
  struct bgpcorsaro_pfxmonitor_state_t *state = STATE(bgpcorsaro);
  khiter_t k;
  khash_t(peer_asn_map) * v;

  if (state == NULL) {
    return 0;
  }

  /* close all the outfile pointers */
  for (i = 0; i < OUTFILE_POINTERS; i++) {
    if (state->outfile_p[i] != NULL) {
      wandio_wdestroy(state->outfile_p[i]);
      state->outfile_p[i] = NULL;
    }
  }
  state->outfile = NULL;
  if (state->poi != NULL) {
    bgpstream_ip_counter_destroy(state->poi);
    state->poi = NULL;
  }

  /* deallocate the dynamic memory in use */
  if (state->overlapping_pfx_cache != NULL) {
    bgpstream_pfx_storage_set_destroy(state->overlapping_pfx_cache);
    state->overlapping_pfx_cache = NULL;
  }

  if (state->non_overlapping_pfx_cache != NULL) {
    bgpstream_pfx_storage_set_destroy(state->non_overlapping_pfx_cache);
    state->non_overlapping_pfx_cache = NULL;
  }

  if (state->peer_asns != NULL) {
    bgpstream_id_set_destroy(state->peer_asns);
    state->peer_asns = NULL;
  }

  if (state->pfx_info != NULL) {
    for (k = kh_begin(state->pfx_info); k != kh_end(state->pfx_info); ++k) {
      if (kh_exist(state->pfx_info, k)) {
        v = kh_val(state->pfx_info, k);
        kh_destroy(peer_asn_map, v);
      }
    }
    kh_destroy(pfx_info_map, state->pfx_info);
    state->pfx_info = NULL;
  }

  if (state->unique_origins != NULL) {
    bgpstream_id_set_destroy(state->unique_origins);
    state->unique_origins = NULL;
  }

  bgpcorsaro_plugin_free_state(bgpcorsaro->plugin_manager, PLUGIN(bgpcorsaro));
  return 0;
}
Пример #6
0
// All the shutdown stuff goes here. Is it really worth bothering to clean up memory just prior to exit?
void shutDown() {
	close(cometSd);
	close(managerSd);
	kmp_destroy(csPool, csPool); // Free the pooled client statuses
	kh_destroy(clientStatuses, clientStatuses); // Free it all
	kh_destroy(queue, queue); // Todo: this probably wont destroy the lists in each queue hash value
	// Todo clean up the libev stuff
}
Пример #7
0
void
sl_destroy(struct sl_interpreter_state *state)
{
        kh_destroy(str, state->symbol_table);
        kh_destroy(str, state->keyword_table);
        sl_free_keep_list(state->keep_list, NULL);
        sl_gc_free_all(state);
        free(state);
}
Пример #8
0
void
mrb_free_symtbls(mrb_state *mrb)
{
  khash_t(s2n) *h = mrb->sym2name;
  khiter_t k;

  for (k = kh_begin(h); k != kh_end(h); ++k)
    if (kh_exist(h, k)) mrb_free(mrb, (char*)kh_value(h, k));
  kh_destroy(s2n,mrb->sym2name);
  kh_destroy(n2s,mrb->name2sym);
}
Пример #9
0
int main(int argc, char *argv[])
{
	int i, l, n = 1000000, ret, c = 0;
	khash_t(str) *h;
	khint_t k;
	h = kh_init(str);
	if (argc > 1) n = atoi(argv[1]);
	for (i = 1; i <= n; ++i) {
		char buf[16];
		int2str(i, 16, buf);
		k = kh_put(str, h, strdup(buf), &ret);
		kh_val(h, k) = i;
	}
	for (i = 1; i <= n; ++i) {
		char buf[16];
		int2str(i, 10, buf);
		k = kh_get(str, h, buf);
		if (k != kh_end(h)) ++c;
	}
	for (k = kh_begin(h); k != kh_end(h); ++k) // explicitly freeing memory takes 10-20% CPU time.
		if (kh_exist(h, k)) free((char*)kh_key(h, k));
	printf("%d\n", c);
	kh_destroy(str, h);
	return 0;
}
Пример #10
0
void
pic_close(pic_state *pic)
{
  pic_allocf allocf = pic->allocf;

  /* clear out root objects */
  pic->cxt = &pic->default_cxt;
  pic->ai = 0;
  pic->halt = pic_invalid_value(pic);
  pic->globals = pic_invalid_value(pic);
  pic->features = pic_invalid_value(pic);
  pic->dyn_env = pic_invalid_value(pic);

  assert(pic->cxt->ai == 0);
  assert(pic->cxt->pc == NULL);
  assert(pic->cxt->fp == NULL);
  assert(pic->cxt->sp == NULL);
  assert(pic->cxt->irep == NULL);
  assert(pic->cxt->prev == NULL);

  /* free all heap objects */
  pic_gc(pic);

  /* free heaps */
  pic_heap_close(pic, pic->heap);

  /* free global stacks */
  kh_destroy(oblist, &pic->oblist);

  /* free GC arena */
  allocf(pic->userdata, pic->arena, 0);
  allocf(pic->userdata, pic, 0);
}
Пример #11
0
void rt_destroy(void)
{
	rt_symbols_destroy();
	rt_code_heap_destroy();

	kh_destroy(rt_hash, object_var_hashes);
}
Пример #12
0
void free_region_table(region_table_t* regions) {
    // Destroy prepared statements
    sqlite3_finalize(regions->insert_region_stmt);
    sqlite3_finalize(regions->find_exact_region_stmt);
    sqlite3_finalize(regions->find_exact_region_type_stmt);
    sqlite3_finalize(regions->find_region_stmt);
    sqlite3_finalize(regions->find_region_type_stmt);
    sqlite3_finalize(regions->remove_exact_region_stmt);
    sqlite3_finalize(regions->remove_region_stmt);
    sqlite3_finalize(regions->get_chromosome_stmt);
    sqlite3_finalize(regions->count_in_chromosome_stmt);

    // Close database
    sqlite3_close_v2(regions->storage);
    
    // Free ordering array
    char **ordering = regions->ordering;
    for (int i = 0; i < regions->max_chromosomes; i++) {
        free(ordering[i]);
    }
    free(ordering);

    // Destroy the chunks hashtable
    kh_destroy(stats_chunks, regions->chunks);

    free(regions);
}
Пример #13
0
void
mrb_gc_free_ht(mrb_state *mrb, struct RHash *c)
{
  khash_t(ht) *h = c->ht;

  kh_destroy(ht, h);
}
Пример #14
0
Файл: bntseq.c Проект: a113n/bwa
bntseq_t *bns_restore(const char *prefix)
{  
	char ann_filename[1024], amb_filename[1024], pac_filename[1024], alt_filename[1024];
	FILE *fp;
	bntseq_t *bns;
	strcat(strcpy(ann_filename, prefix), ".ann");
	strcat(strcpy(amb_filename, prefix), ".amb");
	strcat(strcpy(pac_filename, prefix), ".pac");
	bns = bns_restore_core(ann_filename, amb_filename, pac_filename);
	if (bns == 0) return 0;
	if ((fp = fopen(strcat(strcpy(alt_filename, prefix), ".alt"), "r")) != 0) { // read .alt file if present
		char str[1024];
		khash_t(str) *h;
		int i, absent;
		khint_t k;
		h = kh_init(str);
		for (i = 0; i < bns->n_seqs; ++i) {
			k = kh_put(str, h, bns->anns[i].name, &absent);
			kh_val(h, k) = i;
		}
		while (fscanf(fp, "%s", str) == 1) {
			k = kh_get(str, h, str);
			if (k != kh_end(h))
				bns->anns[kh_val(h, k)].is_alt = 1;
		}
		kh_destroy(str, h);
		fclose(fp);
	}
	return bns;
}
Пример #15
0
static void
init_copy(mrb_state *mrb, mrb_value dest, mrb_value obj)
{
    //if (OBJ_FROZEN(dest)) {
    //    rb_raise(rb_eTypeError, "[bug] frozen object (%s) allocated", rb_obj_classname(dest));
    //}
    //RBASIC(dest)->flags &= ~(T_MASK|FL_EXIVAR);
    //RBASIC(dest)->flags |= RBASIC(obj)->flags & (T_MASK|FL_EXIVAR|FL_TAINT);
    //if (FL_TEST(obj, FL_EXIVAR)) {
    //    mrb_copy_generic_ivar(dest, obj);
    //}
    //mrb_gc_copy_finalizer(dest, obj);
    switch (mrb_type(obj)) {
      case MRB_TT_OBJECT:
      case MRB_TT_CLASS:
      case MRB_TT_MODULE:
        if (ROBJECT(dest)->iv) {
            kh_destroy(iv, ROBJECT(dest)->iv);
            ROBJECT(dest)->iv = 0;
        }
        if (ROBJECT(obj)->iv) {
            ROBJECT(dest)->iv = kh_copy(iv, mrb, ROBJECT(obj)->iv);
        }
        break;

      default:
        break;
    }
    mrb_funcall(mrb, dest, "initialize_copy", 1, obj);
}
Пример #16
0
bam_header_t *sam_header_read2(const char *fn)
{
	bam_header_t *header;
	int c, dret, ret;
	gzFile fp;
	kstream_t *ks;
	kstring_t *str;
	kh_ref_t *hash;
	khiter_t k;
	hash = kh_init(ref);
	fp = (strcmp(fn, "-") == 0)? gzdopen(fileno(stdin), "r") : gzopen(fn, "r");
	assert(fp);
	ks = ks_init(fp);
	str = (kstring_t*)calloc(1, sizeof(kstring_t));
	while (ks_getuntil(ks, 0, str, &dret) > 0) {
		char *s = strdup(str->s);
		int len, i;
		i = kh_size(hash);
		ks_getuntil(ks, 0, str, &dret);
		len = atoi(str->s);
		k = kh_put(ref, hash, s, &ret);
		kh_value(hash, k) = (uint64_t)len<<32 | i;
		if (dret != '\n')
			while ((c = ks_getc(ks)) != '\n' && c != -1);
	}
	ks_destroy(ks);
	gzclose(fp);
	free(str->s); free(str);
	fprintf(stderr, "[sam_header_read2] %d sequences loaded.\n", kh_size(hash));
	header = hash2header(hash);
	kh_destroy(ref, hash);
	return header;
}
Пример #17
0
void
hash_free(hash_t *hash) {
  hash_foreach_remove(hash, hash_internal_free, NULL);

  kh_destroy(str, hash->table);

  free(hash);
}
Пример #18
0
void h2o_cache_destroy(h2o_cache_t *cache)
{
    h2o_cache_clear(cache);
    kh_destroy(cache, cache->table);
    if ((cache->flags & H2O_CACHE_FLAG_MULTITHREADED) != 0)
        pthread_mutex_destroy(&cache->mutex);
    free(cache);
}
Пример #19
0
void graph_cache_dealloc(GraphCache *cache)
{
  kh_destroy(SnodeIdHash, cache->snode_hash);
  db_node_buf_dealloc(&cache->node_buf);
  cache_snode_buf_dealloc(&cache->snode_buf);
  cache_step_buf_dealloc(&cache->step_buf);
  cache_path_buf_dealloc(&cache->path_buf);
}
Пример #20
0
static void sparse_isize_free(isize_data_t data) {
    isize_sparse_data_t *a = data.sparse;
    khint_t k;
    for (k = 0; k < kh_end(a->array); ++k)
        if (kh_exist(a->array, k)) free(kh_val(a->array, k));
    kh_destroy(m32, a->array);
    free(a);
}
Пример #21
0
void h2o_filecache_destroy(h2o_filecache_t *cache)
{
    h2o_filecache_clear(cache);
    assert(kh_size(cache->hash) == 0);
    assert(h2o_linklist_is_empty(&cache->lru));
    kh_destroy(opencache_set, cache->hash);
    free(cache);
}
Пример #22
0
void
tex_group_delete(tex_group_t* self)
{
  shader_group_t* sg;
  sen_assert(self);
  kh_foreach_value(self->sgs, sg, shader_group_delete(sg));
  kh_destroy(hmsp, self->sgs);
  free(self);
}
Пример #23
0
void fai_destroy(faidx_t *fai)
{
	int i;
	for (i = 0; i < fai->n; ++i) free(fai->name[i]);
	free(fai->name);
	kh_destroy(s, fai->hash);
	if (fai->rz) razf_close(fai->rz);
	free(fai);
}
Пример #24
0
static void trans_tbl_destroy(trans_tbl_t *tbl) {
    free(tbl->tid_trans);
    khiter_t iter;
    for (iter = kh_begin(tbl->rg_trans); iter != kh_end(tbl->rg_trans); ++iter) {
        if (kh_exist(tbl->rg_trans, iter)) {
            free(kh_value(tbl->rg_trans, iter));
            free(kh_key(tbl->rg_trans, iter));
        }
    }
    for (iter = kh_begin(tbl->pg_trans); iter != kh_end(tbl->pg_trans); ++iter) {
        if (kh_exist(tbl->pg_trans, iter)) {
            free(kh_value(tbl->pg_trans, iter));
            free(kh_key(tbl->pg_trans, iter));
        }
    }

    kh_destroy(c2c,tbl->rg_trans);
    kh_destroy(c2c,tbl->pg_trans);
}
Пример #25
0
void
htable_ptrs_destroy(htable_ptrs_t *ptr_ht)
{

    if (!ptr_ht) {
        return;
    }
    kh_destroy(ptrs, ptr_ht->ht);
    free(ptr_ht);
}
Пример #26
0
void
mrb_free_symtbl(mrb_state *mrb)
{
  khash_t(n2s) *h = mrb->name2sym;
  khiter_t k;

  for (k = kh_begin(h); k != kh_end(h); k++)
    if (kh_exist(h, k)) mrb_free(mrb, (char*)kh_key(h, k).name);
  kh_destroy(n2s,mrb->name2sym);
}
Пример #27
0
void
blend_group_delete(blend_group_t* self)
{
  tex_group_t* tg;
  sen_assert(self);
  kh_foreach_value(self->tgs, tg, tex_group_delete(tg));
  kh_destroy(hmsp, self->tgs);

  free(self);
}
Пример #28
0
void stk_reg_destroy(reghash_t *h)
{
	khint_t k;
	for (k = 0; k < kh_end(h); ++k) {
		if (kh_exist(h, k)) {
			free(kh_val(h, k).a);
			free((char*)kh_key(h, k));
		}
	}
	kh_destroy(reg, h);
}
Пример #29
0
static void on_dispose(void *_mimemap)
{
    h2o_mimemap_t *mimemap = _mimemap;
    const char *ext;
    h2o_mimemap_type_t *type;

    kh_destroy(typeset, mimemap->typeset);
    kh_foreach(mimemap->extmap, ext, type, {
        h2o_mem_release_shared((char *)ext);
        h2o_mem_release_shared(type);
    });
Пример #30
0
void HashMap_destroy(HashMap* map) {

    for (khint_t k = kh_begin(map->h); k != kh_end(map->h); k++) {
        if (kh_exist(map->h, k)) {
            free((char*) kh_key(map->h, k));
        }
    }

    kh_destroy(str, map->h);
    free(map);
}