Ejemplo n.º 1
0
int sound_manager_alloc(sound_manager** target) {
	if (target == NULL) {
		debug_critical("[sound_manager_alloc] target cannot be NULL");
		return 0;
	}

	if (*target != NULL) {
		debug_warning("[sound_manager_alloc] target points to a non NULL handle, possible memory leak");
	}

	*target = h_malloc(sizeof(sound_manager));

	sound_manager* this = *target;

	this->system_handle = NULL;

	if (FMOD_System_Create(&this->system_handle) != FMOD_OK) {
		debug_critical("[sound_manager_alloc] FMOD failed to allocate sound system");
		h_free(*target);
		*target = NULL;
		return 0;
	}

	if (FMOD_System_Init(this->system_handle, HUNTER_SOUND_MANAGER_CHANNELS, 0, NULL) != FMOD_OK) {
		debug_critical("[sound_manager_alloc] failed to initialize sound system");
		h_free(*target);
		*target = NULL;
		return 0;
	}

	return 1;
}
Ejemplo n.º 2
0
void Server_destroy(Server *srv)
{
    if(srv) {
        if(srv->use_ssl) {
            free(srv->rng_ctx);

            mbedtls_x509_crt_free(&srv->own_cert);
            mbedtls_pk_free(&srv->pk_key);
            // srv->ciphers freed (if non-default) by h_free
        }

        RouteMap_destroy(srv->hosts);
        Server_destroy_handlers(srv);

        bdestroy(srv->bind_addr);
        bdestroy(srv->uuid);
        bdestroy(srv->chroot);
        bdestroy(srv->access_log);
        bdestroy(srv->error_log);
        bdestroy(srv->pid_file);
        bdestroy(srv->control_port);
        bdestroy(srv->default_hostname);

        if(srv->listen_fd >= 0) fdclose(srv->listen_fd);
        h_free(srv);
    }
}
Ejemplo n.º 3
0
void HandlerParser_destroy(HandlerParser *parser)
{
    if(parser != NULL) {
        HandlerParser_reset(parser);
        h_free(parser);
    }
}
Ejemplo n.º 4
0
/* 销毁 */
void h_rbtree_destroy(h_rbtree_st *tree)
{
    if (tree->root)
        node_destroy(tree, tree->root);

    h_free(tree);
}
Ejemplo n.º 5
0
void 
co_tree_destroy(co_obj_t *root)
{
    if(root) {
        h_free(root);
    }
}
Ejemplo n.º 6
0
h_heap_st *h_heap_create(heap_comp_func_t cmp, uint32_t fixed_size)
{
    h_heap_st *hp = h_malloc(sizeof(h_heap_st));

    if(unlikely(hp == NULL))
        return NULL;

    bzero(hp, sizeof(h_heap_st));

    if (cmp)
        hp->__cmp = cmp;
    else
        hp->__cmp = default_cmp;

    if (fixed_size) {
        hp->__fixed = 1;
        hp->__size_base = fixed_size;

        hp->bases = h_malloc(fixed_size * sizeof(void *));
        if (!hp->bases) {
            h_free(hp);
            return NULL;
        }
    }
    return hp;
}
Ejemplo n.º 7
0
void dns_pack_destroy(char *msg)
{
    if (msg)
    {
        h_free(msg);
    }
}
Ejemplo n.º 8
0
ATF_TC_BODY(free, tc)
{
	h_create("test10", 0xc0002000, 0xffffe000, EX_BOUNDZERO);

	h_alloc_subregion(0xc0002000, 0xffffe000, 0x2000,
	    0x10000, 0x10000, 0, 0xc0010000);
	h_alloc_subregion(0xc0002000, 0xffffe000, 0x2000,
	    0x10000, 0x10000, 0, 0xc0020000);

	h_require("test10", 0xc0002000, 0xffffe000, 0x0,
	    "0xc0010000 - 0xc0011fff\n"
	    "0xc0020000 - 0xc0021fff\n");

	h_free(0xc0020000, 0x2000);
	h_require("test10", 0xc0002000, 0xffffe000, 0x0,
	    "0xc0010000 - 0xc0011fff\n");

	h_alloc_subregion(0xc0002000, 0xffffe000, 0x10000,
	    0x10000, 0x10000, 0, 0xc0022000);

	h_require("test10", 0xc0002000, 0xffffe000, 0x0,
	    "0xc0010000 - 0xc0011fff\n"
	    "0xc0022000 - 0xc0031fff\n");

	extent_destroy(ex);
}
Ejemplo n.º 9
0
int sound_alloc(sound** target, sound_manager* system, const char* filename, int streamed) {
	if (target == NULL) {
		debug_critical("[sound_alloc] target cannot be NULL");
		return 0;
	}

	if (*target != NULL) {
		debug_critical("[sound_alloc] target points to non NULL handle, possible memory leak");
	}

	*target = h_malloc(sizeof(sound));

	if (system == NULL) {
		debug_critical("[sound_alloc] system cannot be NULL");
		h_free(*target);
		*target = NULL;
	}

	sound* this = *target;
	memset(this, 0, sizeof(sound));

	this->sound_system = system->system_handle;

	if (FMOD_System_CreateSound(this->sound_system, filename, (streamed) ? FMOD_CREATESTREAM : FMOD_CREATESAMPLE, NULL, &(this->sound_object)) != FMOD_OK) {
		debug_message(filename);
		debug_critical("[sound_alloc] failed to initialize sound, check filename");
		return 0;
	}

	FMOD_Sound_SetMode(this->sound_object, FMOD_LOOP_NORMAL);

	return 1;
}
Ejemplo n.º 10
0
void component_music_trigger_free(void* handle) {
	if (!handle) {
		debug_warning("[component_music_trigger_free] handle cannot be NULL");
		return;
	}

	h_free(handle);
}
Ejemplo n.º 11
0
void Host_destroy(Host *host)
{
    if(host) {
        bdestroy(host->name);
        RouteMap_destroy(host->routes);
        h_free(host);
    }
}
Ejemplo n.º 12
0
void free_tokenizer(TokenizerPtr tok)
{
#ifdef HDEBUG
	h_free (tok, "tok", "free_tokenizer", 110);
#else
	g_free (tok);
#endif
}
Ejemplo n.º 13
0
void component_health_free(void* handle) {
	if (!handle) {
		debug_warning("[component_health_free] handle cannot be NULL");
		return;
	}

	h_free(handle);
}
Ejemplo n.º 14
0
void
svl_crypto_ctx_free(svl_crypto_ctx *ctx)
{
  if (!ctx)
    return;
  if (ctx->keyring_file && ctx->keyring_file != keyring)
    keyring_free(ctx->keyring_file);
  h_free(ctx);
}
Ejemplo n.º 15
0
void Connection_destroy(Connection *conn)
{
    if(conn) {
        Request_destroy(conn->req);
        conn->req = NULL;
        IOBuf_destroy(conn->iob);
        IOBuf_destroy(conn->proxy_iob);
        h_free(conn);
    }
}
Ejemplo n.º 16
0
IOBuf *IOBuf_create(size_t len, int fd, IOBufType type)
{
    IOBuf *buf = h_calloc(sizeof(IOBuf), 1);
    check_mem(buf);

    buf->fd = fd;
    buf->len = len;

    buf->buf = h_malloc(len + 1);
    check_mem(buf->buf);

    hattach(buf->buf, buf);

    buf->type = type;

    if(type == IOBUF_SSL) {
        buf->use_ssl = 1;
        buf->handshake_performed = 0;
        ssl_init(&buf->ssl);
        ssl_set_endpoint(&buf->ssl, SSL_IS_SERVER);
        ssl_set_authmode(&buf->ssl, SSL_VERIFY_NONE);
        havege_init(&buf->hs);
        ssl_set_rng(&buf->ssl, havege_rand, &buf->hs);
        ssl_set_dbg(&buf->ssl, ssl_debug, NULL);
        ssl_set_bio(&buf->ssl, ssl_fdrecv_wrapper, buf, 
                    ssl_fdsend_wrapper, buf);
        ssl_set_session(&buf->ssl, 1, 0, &buf->ssn);
        memset(&buf->ssn, 0, sizeof(buf->ssn));

        buf->send = ssl_send;
        buf->recv = ssl_recv;
        buf->stream_file = ssl_stream_file;
    } else if(type == IOBUF_NULL) {
        buf->send = null_send;
        buf->recv = null_recv;
        buf->stream_file = null_stream_file;
    } else if(type == IOBUF_FILE) {
        buf->send = file_send;
        buf->recv = file_recv;
        buf->stream_file = plain_stream_file;
    } else if(type == IOBUF_SOCKET) {
        buf->send = plaintext_send;
        buf->recv = plaintext_recv;
        buf->stream_file = plain_stream_file;
    } else {
        sentinel("Invalid IOBufType given: %d", type);
    }

    return buf;

error:
    if(buf) h_free(buf);
    return NULL;
}
Ejemplo n.º 17
0
void IOBuf_destroy(IOBuf *buf)
{
    if(buf) {
        if(buf->use_ssl) {
            ssl_close_notify(&buf->ssl);
            ssl_free(&buf->ssl);
        }
        
        fdclose(buf->fd);
        h_free(buf);
    }
}
Ejemplo n.º 18
0
/* 节点递归销毁 */
static void node_destroy(h_rbtree_st *tree, rbtree_node_st *node)
{
    if (node->left)
        node_destroy(tree, node->left);
    if (node->right)
        node_destroy(tree, node->right);

    if ((void *)tree->data_free)
        tree->data_free(node->cs.data);

    h_free(node);
}
Ejemplo n.º 19
0
void sound_manager_free(sound_manager** target) {
	if (target == NULL) {
		debug_warning("[sound_manager_free] target cannot be NULL");
		return;
	}

	if (*target == NULL) {
		debug_warning("[sound_manager_free] target cannot point to NULL");
		return;
	}

	h_free(*target);
	*target = NULL;
}
Ejemplo n.º 20
0
void component_primitive_free(void* handle) {
	if (!handle) {
		debug_warning("[component_primitive_free] handle cannot be NULL");
		return;
	}

	component_primitive* this = (component_primitive*) handle;

	if (this->primitive_handle) {
		primitive_free(&this->primitive_handle);
	}

	h_free(handle);
}
Ejemplo n.º 21
0
void input_free(input** target) {
	if (target == NULL) {
		debug_warning("[input_free] target cannot be NULL");
		return;
	}

	if (*target == NULL) {
		debug_warning("[input_free] target cannot point to NULL");
		return;
	}

	h_free(*target);
	*target = NULL;
}
Ejemplo n.º 22
0
void framebuffer_free(framebuffer** target) {
	if (!target) {
		debug_warning("[framebuffer_free] target cannot be NULL");
		return;
	}

	if (!*target) {
		debug_warning("[framebuffer_free] target cannot point to NULL");
		return;
	}

	glDeleteTextures(1, &(*target)->texture);
	glDeleteFramebuffers(1, &(*target)->fb);
	glDeleteRenderbuffers(1, &(*target)->renderbuffer);

	h_free(*target);
	*target = NULL;
}
Ejemplo n.º 23
0
static Handle alloc_new_handle(H_Type type, const PIVFS& vfs, const VfsPath& pathname, uintptr_t key, size_t flags, va_list* init_args)
{
	HDATA* hd = (HDATA*)pool_alloc(&hpool, 0);
	if(!hd)
		WARN_RETURN(ERR::NO_MEM);
	new(&hd->pathname) VfsPath;

	ssize_t idx = h_idx_from_data(hd);
	RETURN_STATUS_IF_ERR(idx);

	// (don't want to do this before the add-reference exit,
	// so as not to waste tags for often allocated handles.)
	const Tag tag = gen_tag();
	Handle h = handle(idx, tag);	// can't fail.

	hd->h = h;
	hd->key  = key;
	hd->type = type;
	hd->refs = 1;
	if(!(flags & RES_NO_CACHE))
		hd->keep_open = 1;
	if(flags & RES_DISALLOW_RELOAD)
		hd->disallow_reload = 1;
	hd->unique = (flags & RES_UNIQUE) != 0;
	hd->pathname = pathname;

	if(key && !hd->unique)
		key_add(key, h);

	Status err = call_init_and_reload(h, type, hd, vfs, pathname, init_args);
	if(err < 0)
		goto fail;

	return h;

fail:
	// reload failed; free the handle
	hd->keep_open = 0;	// disallow caching (since contents are invalid)
	(void)h_free(h, type);	// (h_free already does WARN_IF_ERR)

	// note: since some uses will always fail (e.g. loading sounds if
	// g_Quickstart), do not complain here.
	return (Handle)err;
}
Ejemplo n.º 24
0
IOBuf *IOBuf_create(size_t len, int fd, IOBufType type)
{
    IOBuf *buf = malloc(sizeof(IOBuf));
    check_mem(buf);

    buf->len = len;
    buf->avail = 0;
    buf->cur = 0;
    buf->closed = 0;
    buf->buf = malloc(len + 1);
    check_mem(buf->buf);
    buf->type = type;
    buf->fd = fd;
    buf->use_ssl = 0;

    if(type == IOBUF_SSL) {
        check(iobuf_ssl_setup(buf) != -1, "Failed to setup SSL.");
        buf->send = ssl_send;
        buf->recv = ssl_recv;
        buf->stream_file = ssl_stream_file;
    } else if(type == IOBUF_NULL) {
        buf->send = null_send;
        buf->recv = null_recv;
        buf->stream_file = null_stream_file;
    } else if(type == IOBUF_FILE) {
        buf->send = file_send;
        buf->recv = file_recv;
        buf->stream_file = plain_stream_file;
    } else if(type == IOBUF_SOCKET) {
        buf->send = plaintext_send;
        buf->recv = plaintext_recv;
        buf->stream_file = plain_stream_file;
    } else {
        sentinel("Invalid IOBufType given: %d", type);
    }

    return buf;

error:
    if(buf) h_free(buf);
    return NULL;
}
Ejemplo n.º 25
0
darray_t *darray_create(size_t element_size, size_t initial_max)
{
    darray_t *array = h_malloc(sizeof(darray_t));
    check_mem(array);

    array->contents = h_calloc(sizeof(void *), initial_max);
    check_mem(array->contents);
    hattach(array->contents, array);

    array->max = initial_max;
    array->end = 0;
    array->element_size = element_size;
    array->expand_rate = DEFAULT_EXPAND_RATE;

    return array;

error:
    if(array) h_free(array);
    return NULL;
}
Ejemplo n.º 26
0
void component_texture_free(void* handle) {
	if (!handle) {
		debug_warning("[component_texture_free] handle cannot be NULL");
		return;
	}

	component_texture* this = (component_texture*) handle;

	for (int i = 0; i < COMPONENT_TEXTURE_MAX_ANIM_COUNT; i++) {
		for (int j = 0; j < this->frame_count[i]; j++) {
			if (!this->texture_buffer[i][j]) {
				continue;
			}

			texture_free(this->texture_buffer[i] + j);
		}
	}

	h_free(this);
}
Ejemplo n.º 27
0
// TODO: what if iterating through all handles is too slow?
Status h_reload(const PIVFS& vfs, const VfsPath& pathname)
{
	H_ScopedLock s;

	const u32 key = fnv_hash(pathname.string().c_str(), pathname.string().length()*sizeof(pathname.string()[0]));

	// destroy (note: not free!) all handles backed by this file.
	// do this before reloading any of them, because we don't specify reload
	// order (the parent resource may be reloaded first, and load the child,
	// whose original data would leak).
	for(HDATA* hd = (HDATA*)hpool.da.base; hd < (HDATA*)(hpool.da.base + hpool.da.pos); hd = (HDATA*)(uintptr_t(hd)+hpool.el_size))
	{
		if(hd->key == 0 || hd->key != key || hd->disallow_reload)
			continue;
		hd->type->dtor(hd->user);
	}

	Status ret = INFO::OK;

	// now reload all affected handles
	size_t i = 0;
	for(HDATA* hd = (HDATA*)hpool.da.base; hd < (HDATA*)(hpool.da.base + hpool.da.pos); hd = (HDATA*)(uintptr_t(hd)+hpool.el_size), i++)
	{
		if(hd->key == 0 || hd->key != key || hd->disallow_reload)
			continue;

		Status err = hd->type->reload(hd->user, vfs, hd->pathname, hd->h);
		// don't stop if an error is encountered - try to reload them all.
		if(err < 0)
		{
			h_free(hd->h, hd->type);
			if(ret == 0)	// don't overwrite first error
				ret = err;
		}
		else
			warn_if_invalid(hd);
	}

	return ret;
}
Ejemplo n.º 28
0
int tp_free(threadpool *pool) {
    if (pool == null || pool->started > 0) {
        return -1;
    }

    // release threadpool if it has been created
    if (pool->ts) {
        pthread_mutex_lock(&pool->lock);

        // free the task queue if it has been initialized
        if (pool->tasks != null) {
            h_foreach(pool->tasks, tp_future_free);
            h_free(pool->tasks);
        }

        free(pool->ts);
        pthread_mutex_destroy(&pool->lock);
        pthread_cond_destroy(&pool->notify);
    }
    free(pool);
    return 0;
}
Ejemplo n.º 29
0
static inline _treenode_t *
_co_tree_delete_r(_treenode_t *root, _treenode_t *current, const char *key, const size_t klen, co_obj_t **value)
{
  DEBUG("Tree current: %s", key);
  if (*key < current->splitchar) 
  {
    current->low = _co_tree_delete_r(root, current->low, key, klen, value); 
  } 
  else if (*key == current->splitchar) 
  { 
    if (klen > 1) 
    {
      // not done yet, keep going but one less
      current->equal = _co_tree_delete_r(root, current->equal, key+1, klen - 1, value);
    } 
    else 
    {
      if(current->value != NULL)
      {
        DEBUG("Found current value.");
        hattach(current->value, NULL);
        current->value->_ref--;
        *value = current->value;
        current->value = NULL;
      }
    }
  } 
  else 
  {
    current->high = _co_tree_delete_r(root, current->high, key, klen, value);
  }

  if(current->low == NULL && current->high == NULL && current->equal == NULL && current->value == NULL)
  {
    h_free(current);
    return NULL;
  }
  else return current; 
}
Ejemplo n.º 30
0
static int Server_load_ciphers(Server *srv, bstring ssl_ciphers_val)
{
    const struct tagbstring bstr_underscore = bsStatic("_");
    const struct tagbstring bstr_dash = bsStatic("-");

    struct bstrList *ssl_cipher_list = bsplit(ssl_ciphers_val, ' ');
    int i = 0, n = 0;
    int *ciphers = NULL;

    check(ssl_cipher_list != NULL && ssl_cipher_list->qty > 0,
            "Invalid cipher list, it must be separated by space ' ' characters "
            "and you need at least one.  Or, just leave it out for defaults.");

    ciphers = h_calloc(ssl_cipher_list->qty + 1, sizeof(int));
    check_mem(ciphers);

    for(i = 0; i < ssl_cipher_list->qty; i++) {
        bstring cipher = ssl_cipher_list->entry[i];

        int id = -1;

        // Replace underscores (used in old ciphers) with dashes
        bfindreplace(cipher, &bstr_underscore, &bstr_dash, 0);

        // Search legacy cipher list
        for(n = 0; legacy_cipher_table[n].name != NULL; ++n)
        {
            if(biseqcstr(cipher, legacy_cipher_table[n].name))
            {
                id = legacy_cipher_table[n].id;
                break;
            }
        }

        if(id != -1 && mbedtls_ssl_ciphersuite_from_id(id) != NULL)
        {
            ciphers[i] = id;
        }
        else
        {
            // Search polarssl cipher list
            const mbedtls_ssl_ciphersuite_t * suite =
                mbedtls_ssl_ciphersuite_from_string(bdata(cipher));

            if (suite != NULL)
                ciphers[i] = suite->id;
            else
                sentinel("Unrecognized cipher: %s", bdata(cipher));
        }
    }

    bstrListDestroy(ssl_cipher_list);
    ciphers[i] = 0;
    srv->ciphers = ciphers;
    hattach(ciphers, srv);

    return 0;
error:
    if(ssl_cipher_list) bstrListDestroy(ssl_cipher_list);
    if(ciphers != NULL) h_free(ciphers);
    return -1;
}