예제 #1
0
파일: browscap.c 프로젝트: Synchro/php-src
static void browscap_entry_dtor_persistent(zval *zvalue)
{
	browscap_entry *entry = Z_PTR_P(zvalue);
	zend_string_release(entry->pattern);
	if (entry->parent) {
		zend_string_release(entry->parent);
	}
	pefree(entry, 1);
}
예제 #2
0
파일: http.c 프로젝트: shinezhou/http
/* if the curl iterm pool is full replace the first item in the pool for the next call*/
static CURL* replace(char *key, uint key_len) {
	curl_item *first;
	first = items[0];
	if (first == NULL) return NULL;
	pefree(first->key, 1);
	first->key = key;
	first->key_len = key_len;
	return first->curl;
}
예제 #3
0
/* {{{ mysql_handle_closer */
static int mysql_handle_closer(pdo_dbh_t *dbh)
{
	pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;

	PDO_DBG_ENTER("mysql_handle_closer");
	PDO_DBG_INF_FMT("dbh=%p", dbh);
	if (H) {
		if (H->server) {
			mysql_close(H->server);
		}
		if (H->einfo.errmsg) {
			pefree(H->einfo.errmsg, dbh->is_persistent);
		}
		pefree(H, dbh->is_persistent);
		dbh->driver_data = NULL;
	}
	PDO_DBG_RETURN(0);
}
예제 #4
0
파일: browscap.c 프로젝트: Synchro/php-src
static void browscap_bdata_dtor(browser_data *bdata, int persistent) /* {{{ */
{
	if (bdata->htab != NULL) {
		uint32_t i;

		zend_hash_destroy(bdata->htab);
		pefree(bdata->htab, persistent);
		bdata->htab = NULL;

		for (i = 0; i < bdata->kv_used; i++) {
			zend_string_release(bdata->kv[i].key);
			zend_string_release(bdata->kv[i].value);
		}
		pefree(bdata->kv, persistent);
		bdata->kv = NULL;
	}
	bdata->filename[0] = '\0';
}
예제 #5
0
파일: browscap.c 프로젝트: AmesianX/php-src
static void browscap_bdata_dtor(browser_data *bdata, int persistent) /* {{{ */
{
	if (bdata->htab != NULL) {
		zend_hash_destroy(bdata->htab);
		pefree(bdata->htab, persistent);
		bdata->htab = NULL;
	}
	bdata->filename[0] = '\0';
	/* current_section_* are only used during parsing */
}
예제 #6
0
/** {{{ static void yaf_config_zval_dtor(zval **value)
 */
static void yaf_config_zval_dtor(zval **value) {
	if (*value) {
		switch(Z_TYPE_PP(value)) {
			case IS_STRING:
			case IS_CONSTANT:
				CHECK_ZVAL_STRING(*value);
				pefree((*value)->value.str.val, 1);
				pefree(*value, 1);
				break;
			case IS_ARRAY:
			case IS_CONSTANT_ARRAY: {
				zend_hash_destroy((*value)->value.ht);
				pefree((*value)->value.ht, 1);
				pefree(*value, 1);
			}
			break;
		}
	}
}
예제 #7
0
/* {{{ php_mb_regex_globals_alloc */
zend_mb_regex_globals *php_mb_regex_globals_alloc(void)
{
	zend_mb_regex_globals *pglobals = pemalloc(
			sizeof(zend_mb_regex_globals), 1);
	if (SUCCESS != _php_mb_regex_globals_ctor(pglobals)) {
		pefree(pglobals, 1);
		return NULL;
	}
	return pglobals;
}
/* {{{ 	void solr_destroy_document(void *document) */
PHP_SOLR_API void solr_destroy_document(void *document)
{
	solr_document_t *doc_entry = (solr_document_t *) document;

	/* Release all the field_lists one at a time with solr_destroy_field_list */
	zend_hash_destroy(doc_entry->fields);

	/* Deallocate memory for the fields HashTable */
	pefree(doc_entry->fields, SOLR_DOCUMENT_FIELD_PERSISTENT);
}
static void connection_resource_destructor(amqp_connection_resource *resource, int persistent TSRMLS_DC)
{
	assert(resource != NULL);

#ifndef PHP_WIN32
	void * old_handler;

	/*
	If we are trying to close the connection and the connection already closed, it will throw
	SIGPIPE, which is fine, so ignore all SIGPIPES
	*/

	/* Start ignoring SIGPIPE */
	old_handler = signal(SIGPIPE, SIG_IGN);
#endif

	if (resource->parent) {
		resource->parent->connection_resource = NULL;
	}

	if (resource->slots) {
		php_amqp_prepare_for_disconnect(resource TSRMLS_CC);

		pefree(resource->slots, persistent);
		resource->slots = NULL;
	}

	/* connection may be closed in case of previous failure */
	if (resource->is_connected) {
		amqp_connection_close(resource->connection_state, AMQP_REPLY_SUCCESS);
	}

	amqp_destroy_connection(resource->connection_state);

#ifndef PHP_WIN32
	/* End ignoring of SIGPIPEs */
	signal(SIGPIPE, old_handler);
#endif

	pefree(resource, persistent);
}
예제 #10
0
static int sqlite_handle_closer(pdo_dbh_t *dbh) /* {{{ */
{
	pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data;

	if (H) {
		pdo_sqlite_error_info *einfo = &H->einfo;

		pdo_sqlite_cleanup_callbacks(H);
		if (H->db) {
			sqlite3_close(H->db);
			H->db = NULL;
		}
		if (einfo->errmsg) {
			pefree(einfo->errmsg, dbh->is_persistent);
			einfo->errmsg = NULL;
		}
		pefree(H, dbh->is_persistent);
		dbh->driver_data = NULL;
	}
	return 0;
}
예제 #11
0
/* 销毁持久型zval变量,从里面的实现来看,只能销毁string、array、constant */
static void yaf_config_zval_dtor(zval **value) {
	if (*value) {
		switch(Z_TYPE_PP(value)) {
			case IS_STRING:
			case IS_CONSTANT:
				/* if (Z_STRVAL_P(z)[ Z_STRLEN_P(z) ] != '\0') { zend_err..... */
				CHECK_ZVAL_STRING(*value);
				pefree((*value)->value.str.val, 1);
				pefree(*value, 1);
				break;
			case IS_ARRAY:
			case IS_CONSTANT_ARRAY: {
				/* 销毁hash表,删除持久性内存的变量 */
				zend_hash_destroy((*value)->value.ht);
				pefree((*value)->value.ht, 1);
				pefree(*value, 1);
			}
			break;
		}
	}
}
예제 #12
0
int _pdo_sqlite_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line) /* {{{ */
{
	pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data;
	pdo_error_type *pdo_err = stmt ? &stmt->error_code : &dbh->error_code;
	pdo_sqlite_error_info *einfo = &H->einfo;

	einfo->errcode = sqlite3_errcode(H->db);
	einfo->file = file;
	einfo->line = line;

	if (einfo->errcode != SQLITE_OK) {
		if (einfo->errmsg) {
			pefree(einfo->errmsg, dbh->is_persistent);
		}
		einfo->errmsg = pestrdup((char*)sqlite3_errmsg(H->db), dbh->is_persistent);
	} else { /* no error */
		strncpy(*pdo_err, PDO_ERR_NONE, sizeof(PDO_ERR_NONE));
		return 0;
	}
	switch (einfo->errcode) {
		case SQLITE_NOTFOUND:
			strncpy(*pdo_err, "42S02", sizeof("42S02"));
			break;

		case SQLITE_INTERRUPT:
			strncpy(*pdo_err, "01002", sizeof("01002"));
			break;

		case SQLITE_NOLFS:
			strncpy(*pdo_err, "HYC00", sizeof("HYC00"));
			break;

		case SQLITE_TOOBIG:
			strncpy(*pdo_err, "22001", sizeof("22001"));
			break;

		case SQLITE_CONSTRAINT:
			strncpy(*pdo_err, "23000", sizeof("23000"));
			break;

		case SQLITE_ERROR:
		default:
			strncpy(*pdo_err, "HY000", sizeof("HY000"));
			break;
	}

	if (!dbh->methods) {
		zend_throw_exception_ex(php_pdo_get_exception(), einfo->errcode, "SQLSTATE[%s] [%d] %s",
				*pdo_err, einfo->errcode, einfo->errmsg);
	}

	return einfo->errcode;
}
예제 #13
0
static void* zend_hash_add_constant(HashTable *ht, zend_string *key, zend_constant *c)
{
	void *ret;
	zend_constant *copy = pemalloc(sizeof(zend_constant), c->flags & CONST_PERSISTENT);

	memcpy(copy, c, sizeof(zend_constant));
	ret = zend_hash_add_ptr(ht, key, copy);
	if (!ret) {
		pefree(copy, c->flags & CONST_PERSISTENT);
	}
	return ret;
}
예제 #14
0
void php_mongo_server_free(mongo_server *server, int persist TSRMLS_DC) {
  // return this connection to the pool
  mongo_util_pool_done(server TSRMLS_CC);

  if (server->host) {
    pefree(server->host, persist);
    server->host = 0;
  }
  if (server->label) {
    pefree(server->label, persist);
    server->label = 0;
  }
  if (server->username) {
    pefree(server->username, persist);
    server->username = 0;
  }
  if (server->password) {
    pefree(server->password, persist);
    server->password = 0;
  }
  if (server->db) {
    pefree(server->db, persist);
    server->db = 0;
  }

  pefree(server, persist);
}
예제 #15
0
파일: filter.c 프로젝트: PeeHaa/php-src
PHPAPI int php_stream_bucket_split(php_stream_bucket *in, php_stream_bucket **left, php_stream_bucket **right, size_t length)
{
	*left = (php_stream_bucket*)pecalloc(1, sizeof(php_stream_bucket), in->is_persistent);
	*right = (php_stream_bucket*)pecalloc(1, sizeof(php_stream_bucket), in->is_persistent);

	if (*left == NULL || *right == NULL) {
		goto exit_fail;
	}

	(*left)->buf = pemalloc(length, in->is_persistent);
	(*left)->buflen = length;
	memcpy((*left)->buf, in->buf, length);
	(*left)->refcount = 1;
	(*left)->own_buf = 1;
	(*left)->is_persistent = in->is_persistent;

	(*right)->buflen = in->buflen - length;
	(*right)->buf = pemalloc((*right)->buflen, in->is_persistent);
	memcpy((*right)->buf, in->buf + length, (*right)->buflen);
	(*right)->refcount = 1;
	(*right)->own_buf = 1;
	(*right)->is_persistent = in->is_persistent;

	return SUCCESS;

exit_fail:
	if (*right) {
		if ((*right)->buf) {
			pefree((*right)->buf, in->is_persistent);
		}
		pefree(*right, in->is_persistent);
	}
	if (*left) {
		if ((*left)->buf) {
			pefree((*left)->buf, in->is_persistent);
		}
		pefree(*left, in->is_persistent);
	}
	return FAILURE;
}
예제 #16
0
static zend_always_inline void i_zend_hash_bucket_delete(HashTable *ht, Bucket *p)
{
#ifdef ZEND_SIGNALS
	TSRMLS_FETCH();
#endif

	HANDLE_BLOCK_INTERRUPTIONS();
	if (p->pLast) {
		p->pLast->pNext = p->pNext;
	} else {
		ht->arBuckets[p->h & ht->nTableMask] = p->pNext;
	}
	if (p->pNext) {
		p->pNext->pLast = p->pLast;
	}
	if (p->pListLast != NULL) {
		p->pListLast->pListNext = p->pListNext;
	} else { 
		/* Deleting the head of the list */
		ht->pListHead = p->pListNext;
	}
	if (p->pListNext != NULL) {
		p->pListNext->pListLast = p->pListLast;
	} else {
		/* Deleting the tail of the list */
		ht->pListTail = p->pListLast;
	}
	if (ht->pInternalPointer == p) {
		ht->pInternalPointer = p->pListNext;
	}
	ht->nNumOfElements--;
	if (ht->pDestructor) {
		ht->pDestructor(p->pData);
	}
	if (p->pData != &p->pDataPtr) {
		pefree(p->pData, ht->persistent);
	}
	pefree(p, ht->persistent);
	HANDLE_UNBLOCK_INTERRUPTIONS();
}
예제 #17
0
파일: browscap.c 프로젝트: AmesianX/php-src
static int browscap_read_file(char *filename, browser_data *browdata, int persistent) /* {{{ */
{
	zend_file_handle fh = {{0}};
	
	if (filename == NULL || filename[0] == '\0') {
		return FAILURE;
	}
	
	browdata->htab = pemalloc(sizeof *browdata->htab, persistent);
	if (browdata->htab == NULL) {
		return FAILURE;
	}

	zend_hash_init_ex(browdata->htab, 0, NULL,
			(dtor_func_t) (persistent?browscap_entry_dtor_persistent
									 :browscap_entry_dtor_request),
			persistent, 0);

	fh.handle.fp = VCWD_FOPEN(filename, "r");
	fh.opened_path = NULL;
	fh.free_filename = 0;
	if (!fh.handle.fp) {
		zend_hash_destroy(browdata->htab);
		pefree(browdata->htab, persistent);
		browdata->htab = NULL;
		zend_error(E_CORE_WARNING, "Cannot open '%s' for reading", filename);
		return FAILURE;
	}
	fh.filename = filename;
	fh.type = ZEND_HANDLE_FP;
	browdata->current_section_name = NULL;
	zend_parse_ini_file(&fh, 1, ZEND_INI_SCANNER_RAW,
			(zend_ini_parser_cb_t) php_browscap_parser_cb, browdata);
	if (browdata->current_section_name != NULL) {
		pefree(browdata->current_section_name, persistent);
		browdata->current_section_name = NULL;
	}
	
	return SUCCESS;
}
예제 #18
0
static void
php_cassandra_session_dtor(php5to7_zend_resource rsrc TSRMLS_DC)
{
  cassandra_psession *psession = (cassandra_psession*) rsrc->ptr;

  if (psession) {
    cass_future_free(psession->future);
    cass_session_free(psession->session);
    pefree(psession, 1);
    CASSANDRA_G(persistent_sessions)--;
    rsrc->ptr = NULL;
  }
}
예제 #19
0
ZEND_API void zend_ptr_stack_clean(zend_ptr_stack *stack, void (*func)(void *), zend_bool free_elements)
{
	zend_ptr_stack_apply(stack, func);
	if (free_elements) {
		int i = stack->top;

		while (--i >= 0) {
			pefree(stack->elements[i], stack->persistent);
		}
	}
	stack->top = 0;
	stack->top_element = stack->elements;
}
static int compact_hash_table(HashTable *ht)
{
	uint i = 3;
	uint j;
	uint nSize;
	Bucket *d;
	Bucket *p;

	if (!ht->nNumOfElements || (ht->u.flags & HASH_FLAG_PACKED)) {
		/* Empty tables don't allocate space for Buckets */
		return 1;
	}

	if (ht->nNumOfElements >= 0x80000000) {
		/* prevent overflow */
		nSize = 0x80000000;
	} else {
		while ((1U << i) < ht->nNumOfElements) {
			i++;
		}
		nSize = 1 << i;
	}

	if (nSize >= ht->nTableSize) {
		/* Keep the size */
		return 1;
	}

	d = (Bucket *)pemalloc(nSize * (sizeof(Bucket) + sizeof(zend_uint)), ht->u.flags & HASH_FLAG_PERSISTENT);
	if (!d) {
		return 0;
	}

	for (i = 0, j = 0; i < ht->nNumUsed; i++) {
		p = ht->arData + i;
		if (Z_TYPE(p->val) != IS_UNDEF) {
			d[j++] = *p;
		}
	}
	ht->nNumUsed = j;

	pefree(ht->arData, ht->u.flags & HASH_FLAG_PERSISTENT);

	ht->arData = d;
	ht->arHash = (zend_uint *)(d + nSize);
	ht->nTableSize = nSize;
	ht->nTableMask = ht->nTableSize - 1;
	zend_hash_rehash(ht);
	
	return 1;
}
예제 #21
0
static php_vedis_t *
php_vedis_new(char *storage, int storage_len, zend_bool is_persistent TSRMLS_DC)
{
    php_vedis_t *vedis;
    char *filepath = NULL, *stragepath = NULL;

    vedis = pecalloc(1, sizeof(php_vedis_t), is_persistent);

    if (!storage || storage_len <= 0) {
        stragepath = NULL;
    } else if (strcmp(storage, ":mem:") != 0) {
        if (!(filepath = expand_filepath(storage, NULL TSRMLS_CC))) {
            pefree(vedis, is_persistent);
            return NULL;
        }
        stragepath = filepath;
    } else {
        stragepath = storage;
    }

    if (vedis_open(&(vedis->store), stragepath) != VEDIS_OK) {
        if (filepath) {
            efree(filepath);
        }
        pefree(vedis, is_persistent);
        return NULL;
    }

    if (filepath) {
        efree(filepath);
    }

    vedis->storage = storage;
    vedis->is_persistent = is_persistent;
    vedis->pid = getpid();

    return vedis;
}
예제 #22
0
ZEND_API void zend_hash_graceful_reverse_destroy(HashTable *ht)
{
	IS_CONSISTENT(ht);

	while (ht->pListTail != NULL) {
		zend_hash_bucket_delete(ht, ht->pListTail);
	}

	if (ht->nTableMask) {
		pefree(ht->arBuckets, ht->persistent);
	}

	SET_INCONSISTENT(HT_DESTROYED);
}
예제 #23
0
ZEND_API void zend_hash_graceful_destroy(HashTable *ht)
{
	Bucket *p;

	IS_CONSISTENT(ht);

	p = ht->pListHead;
	while (p != NULL) {
		p = zend_hash_apply_deleter(ht, p);
	}
	pefree(ht->arBuckets, ht->persistent);

	SET_INCONSISTENT(HT_DESTROYED);
}
예제 #24
0
void free_zend_constant(zval *zv)
{
	zend_constant *c = Z_PTR_P(zv);

	if (!(c->flags & CONST_PERSISTENT)) {
		zval_dtor(&c->value);
	} else {
		zval_internal_dtor(&c->value);
	}
	if (c->name) {
		zend_string_release(c->name);
	}
	pefree(c, c->flags & CONST_PERSISTENT);
}
예제 #25
0
파일: dwarfopen.c 프로젝트: GYGit/reactos
void
dwarfclose(Dwarf *d)
{
	free(d->abbrev.data);
	free(d->aranges.data);
	free(d->frame.data);
	free(d->line.data);
	free(d->pubnames.data);
	free(d->ranges.data);
	free(d->str.data);
	free(d->info.data);
	pefree(d->pe);
	free(d);
}
예제 #26
0
ZEND_API void zend_llist_destroy(zend_llist *l)
{
	zend_llist_element *current=l->head, *next;
	
	while (current) {
		next = current->next;
		if (l->dtor) {
			l->dtor(current->data);
		}
		pefree(current, l->persistent);
		current = next;
	}

	l->count = 0;
}
예제 #27
0
파일: ref.c 프로젝트: datastax/php-driver
void
php_driver_del_peref(php_driver_ref **ref_ptr, int persistent)
{
  php_driver_ref *ref = *ref_ptr;
  if (ref) {
    ref->count--;

    if (ref->count <= 0) {
      ref->destruct(ref->data);
      ref->data = NULL;
      pefree(ref, persistent);
      *ref_ptr = NULL;
    }
  }
}
예제 #28
0
ZEND_API void zend_hash_destroy(HashTable *ht)
{
	Bucket *p, *q;

	IS_CONSISTENT(ht);

	SET_INCONSISTENT(HT_IS_DESTROYING);

	p = ht->pListHead;
	while (p != NULL) {
		q = p;
		p = p->pListNext;
		if (ht->pDestructor) {
			ht->pDestructor(q->pData);
		}
		if (q->pData != &q->pDataPtr) {
			pefree(q->pData, ht->persistent);
		}
		pefree(q, ht->persistent);
	}
	pefree(ht->arBuckets, ht->persistent);

	SET_INCONSISTENT(HT_DESTROYED);
}
예제 #29
0
파일: zmq.c 프로젝트: dermoth/php-zmq
/* {{{ static php_zmq_context *php_zmq_context_new(long io_threads, zend_bool is_persistent TSRMLS_DC)
	Create a new zmq context
*/
static php_zmq_context *php_zmq_context_new(long io_threads, zend_bool is_persistent TSRMLS_DC)
{
	php_zmq_context *context;

	context        = pecalloc(1, sizeof(php_zmq_context), is_persistent);
	context->z_ctx = zmq_init(io_threads);
	
	if (!context->z_ctx) {
		pefree(context, is_persistent);
		return NULL;
	}
	
	context->io_threads    = io_threads;
	context->is_persistent = is_persistent;
	return context;
}
예제 #30
0
int _record_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line, const char *sql_state,  int error_code, const char *error_message)
{
	pdo_nuodb_db_handle *H = (pdo_nuodb_db_handle *)dbh->driver_data;
	pdo_error_type *pdo_err;
	pdo_nuodb_error_info *einfo;
	pdo_nuodb_stmt *S = NULL;

	PDO_DBG_ENTER("_record_error");
	PDO_DBG_INF_FMT("file=%s line=%d", file, line);
	PDO_DBG_INF_FMT("sql_state=%s  error_code=%d  error_message=%s", sql_state, error_code, error_message);
	if (stmt) {
		S = (pdo_nuodb_stmt*)stmt->driver_data;
		PDO_DBG_INF_FMT("sql=%s", S->sql);
		pdo_err = &stmt->error_code;
		einfo   = &S->einfo;
	} else {
		pdo_err = &dbh->error_code;
		einfo   = &H->einfo;
	}

	einfo->errcode = error_code;
	einfo->file = file;
	einfo->line = line;
	if (einfo->errmsg) {
		pefree(einfo->errmsg, dbh->is_persistent);
		einfo->errmsg = NULL;
	}

	if (!einfo->errcode) { /* no error */
		strcpy(*pdo_err, PDO_ERR_NONE);
		PDO_DBG_RETURN(0);
	}

	einfo->errmsg = pestrdup(error_message, dbh->is_persistent);
	strncpy(*pdo_err, sql_state, 6);


	if (!dbh->methods) {
		TSRMLS_FETCH();
		PDO_DBG_INF("Throwing exception");
		zend_throw_exception_ex(php_pdo_get_exception(), einfo->errcode TSRMLS_CC, "SQLSTATE[%s] [%d] %s",
				*pdo_err, einfo->errcode, einfo->errmsg);
	}

	PDO_DBG_RETURN(einfo->errcode);

}