void _php_ibase_free_event(ibase_event *event) /* {{{ */ { unsigned short i; event->state = DEAD; if (event->link != NULL) { ibase_event **node; zend_list_delete(event->link_res); if (event->link->handle != 0 && isc_cancel_events(IB_STATUS, &event->link->handle, &event->event_id)) { _php_ibase_error(); } /* delete this event from the link struct */ for (node = &event->link->event_head; *node != event; node = &(*node)->event_next); *node = event->event_next; } if (Z_TYPE(event->callback) != IS_UNDEF) { zval_ptr_dtor(&event->callback); ZVAL_UNDEF(&event->callback); _php_ibase_event_free(event->event_buffer,event->result_buffer); for (i = 0; i < event->event_count; ++i) { if (event->events[i]) { efree(event->events[i]); } } efree(event->events); } }
static void istream_destructor(php_istream *stm) { if (stm->res) { zend_resource *res = stm->res; stm->res = NULL; zend_list_delete(res); return; } if (stm->refcount > 0) { CoDisconnectObject((IUnknown*)stm, 0); } zend_list_delete(stm->stream->res); CoTaskMemFree(stm); }
ZEND_METHOD(YConsistent,consistent_end){ zval *object = getThis(); zval **conhash_prop; if(zend_hash_find(Z_OBJPROP_P(object),"conhash",sizeof("conhash"),(void **)&conhash_prop) == FAILURE){ RETURN_NULL(); } if(zend_list_delete(Z_LVAL_PP(conhash_prop)) == FAILURE){ RETURN_FALSE; } RETURN_TRUE; }
static void php_set_default_dir(int id TSRMLS_DC) { if (DIRG(default_dir)!=-1) { zend_list_delete(DIRG(default_dir)); } if (id != -1) { zend_list_addref(id); } DIRG(default_dir) = id; }
static void php_set_default_dir(zend_resource *res) { if (DIRG(default_dir)) { zend_list_delete(DIRG(default_dir)); } if (res) { GC_REFCOUNT(res)++; } DIRG(default_dir) = res; }
static ULONG STDMETHODCALLTYPE stm_release(IStream *This) { ULONG ret; FETCH_STM(); ret = InterlockedDecrement(&stm->refcount); if (ret == 0) { /* destroy it */ if (stm->res) zend_list_delete(stm->res); } return ret; }
ZEND_API void convert_to_boolean(zval *op) { char *strval; int tmp; switch (op->type) { case IS_BOOL: break; case IS_NULL: op->value.lval = 0; break; case IS_RESOURCE: zend_list_delete(op->value.lval); /* break missing intentionally */ case IS_LONG: op->value.lval = (op->value.lval ? 1 : 0); break; case IS_DOUBLE: op->value.lval = (op->value.dval ? 1 : 0); break; case IS_STRING: strval = op->value.str.val; if (op->value.str.len == 0 || (op->value.str.len==1 && op->value.str.val[0]=='0')) { op->value.lval = 0; } else { op->value.lval = 1; } STR_FREE(strval); break; case IS_ARRAY: tmp = (zend_hash_num_elements(op->value.ht)?1:0); zval_dtor(op); op->value.lval = tmp; break; case IS_OBJECT: tmp = (zend_hash_num_elements(op->value.obj.properties)?1:0); zval_dtor(op); op->value.lval = tmp; break; default: zval_dtor(op); op->value.lval = 0; break; } op->type = IS_BOOL; }
static int php_ssh2_channel_stream_close(php_stream *stream, int close_handle TSRMLS_DC) { php_ssh2_channel_data *abstract = (php_ssh2_channel_data*)stream->abstract; if (!abstract->refcount || (--(*(abstract->refcount)) == 0)) { /* Last one out, turn off the lights */ if (abstract->refcount) { efree(abstract->refcount); } libssh2_channel_eof(abstract->channel); libssh2_channel_free(abstract->channel); zend_list_delete(abstract->session_rsrc); } efree(abstract); return 0; }
void _php_curl_multi_cleanup_list(void *data) /* {{{ */ { zval *z_ch = (zval *)data; php_curl *ch; if (!z_ch) { return; } if (!Z_RES_P(z_ch)->ptr) { return; } if ((ch = (php_curl *)zend_fetch_resource(Z_RES_P(z_ch), le_curl_name, le_curl)) == NULL) { return; } zend_list_delete(Z_RES_P(z_ch)); }
static void php_enchant_dict_free(zend_resource *rsrc) /* {{{ */ { if (rsrc->ptr) { enchant_dict *pdict = (enchant_dict *)rsrc->ptr; if (pdict) { enchant_broker *pbroker = pdict->pbroker; if (pdict->pdict && pbroker) { enchant_broker_free_dict(pbroker->pbroker, pdict->pdict); } pbroker->dict[pdict->id] = NULL; efree(pdict); zend_list_delete(pbroker->rsrc); } } }
/* ArchiveReader::close {{{ * */ ZEND_METHOD(ArchiveReader, close) { zval *this = getThis(); int resourse_id; zend_error_handling error_handling; zend_replace_error_handling(EH_THROW, ce_ArchiveException, &error_handling TSRMLS_CC); if ((resourse_id = _archive_get_rsrc_id(this TSRMLS_CC))) { add_property_resource(this, "fd", 0); zend_list_delete(resourse_id); zend_restore_error_handling(&error_handling TSRMLS_CC); RETURN_TRUE; } php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to close archive file descriptor"); zend_restore_error_handling(&error_handling TSRMLS_CC); }
/* {{{ php_oci_lob_free() Close LOB descriptor and free associated resources */ void php_oci_lob_free (php_oci_descriptor *descriptor) { if (!descriptor || !descriptor->connection) { return; } if (descriptor->connection->descriptors) { /* delete descriptor from the hash */ zend_hash_index_del(descriptor->connection->descriptors, descriptor->index); if (zend_hash_num_elements(descriptor->connection->descriptors) == 0) { descriptor->connection->descriptor_count = 0; } else { if (descriptor->index + 1 == descriptor->connection->descriptor_count) { /* If the descriptor being freed is the end-most one * allocated, then the descriptor_count is reduced so * a future descriptor can reuse the hash table index. * This can prevent the hash index range increasing in * the common case that each descriptor is * allocated/used/freed before another descriptor is * needed. However it is possible that a script frees * descriptors in arbitrary order which would prevent * descriptor_count ever being reduced to zero until * zend_hash_num_elements() returns 0. */ descriptor->connection->descriptor_count--; } } } /* flushing Lobs & Files with buffering enabled */ if ((descriptor->type == OCI_DTYPE_FILE || descriptor->type == OCI_DTYPE_LOB) && descriptor->buffering == PHP_OCI_LOB_BUFFER_USED) { php_oci_lob_flush(descriptor, OCI_LOB_BUFFER_FREE); } if (descriptor->type == OCI_DTYPE_LOB) { php_oci_temp_lob_close(descriptor); } PHP_OCI_CALL(OCIDescriptorFree, (descriptor->descriptor, descriptor->type)); zend_list_delete(descriptor->connection->id); efree(descriptor); }
ZEND_API void convert_to_double(zval *op) { char *strval; double tmp; switch (op->type) { case IS_NULL: op->value.dval = 0.0; break; case IS_RESOURCE: zend_list_delete(op->value.lval); /* break missing intentionally */ case IS_BOOL: case IS_LONG: op->value.dval = (double) op->value.lval; break; case IS_DOUBLE: break; case IS_STRING: strval = op->value.str.val; op->value.dval = strtod(strval, NULL); STR_FREE(strval); break; case IS_ARRAY: tmp = (zend_hash_num_elements(op->value.ht)?1:0); zval_dtor(op); op->value.dval = tmp; break; case IS_OBJECT: tmp = (zend_hash_num_elements(op->value.obj.properties)?1:0); zval_dtor(op); op->value.dval = tmp; break; default: zend_error(E_WARNING, "Cannot convert to real value (type=%d)", op->type); zval_dtor(op); op->value.dval = 0; break; } op->type = IS_DOUBLE; }
/* {{{ php_oci_collection_close() Destroy collection and all associated resources */ void php_oci_collection_close(php_oci_collection *collection) { php_oci_connection *connection = collection->connection; sword errstatus; if (collection->collection) { PHP_OCI_CALL_RETURN(errstatus, OCIObjectFree, (connection->env, connection->err, (dvoid *)collection->collection, (ub2)OCI_OBJECTFREE_FORCE)); if (errstatus != OCI_SUCCESS) { connection->errcode = php_oci_error(connection->err, errstatus); PHP_OCI_HANDLE_ERROR(connection, connection->errcode); } else { connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */ } } zend_list_delete(collection->connection->id); efree(collection); return; }
void _php_curl_multi_cleanup_list(void *data) /* {{{ */ { zval *z_ch = (zval *)data; php_curl *ch; TSRMLS_FETCH(); if (!z_ch) { return; } ch = (php_curl *) zend_fetch_resource(&z_ch TSRMLS_CC, -1, le_curl_name, NULL, 1, le_curl); if (!ch) { return; } if (ch->uses) { ch->uses--; } else { zend_list_delete(Z_LVAL_P(z_ch)); } }
ZEND_API void convert_scalar_to_number(zval *op) { switch (op->type) { case IS_STRING: { char *strval; strval = op->value.str.val; switch ((op->type=is_numeric_string(strval, op->value.str.len, &op->value.lval, &op->value.dval))) { case IS_DOUBLE: case IS_LONG: break; #if 0 && WITH_BCMATH case FLAG_IS_BC: op->type = IS_DOUBLE; /* may have lost significant digits */ break; #endif default: op->value.lval = strtol(op->value.str.val, NULL, 10); op->type = IS_LONG; break; } STR_FREE(strval); break; } case IS_BOOL: op->type = IS_LONG; break; case IS_RESOURCE: zend_list_delete(op->value.lval); op->type = IS_LONG; break; case IS_NULL: op->type = IS_LONG; op->value.lval = 0; break; } }
PHPAPI php_stream_filter *php_stream_filter_remove(php_stream_filter *filter, int call_dtor) { if (filter->prev) { filter->prev->next = filter->next; } else { filter->chain->head = filter->next; } if (filter->next) { filter->next->prev = filter->prev; } else { filter->chain->tail = filter->prev; } if (filter->res) { zend_list_delete(filter->res); } if (call_dtor) { php_stream_filter_free(filter); return NULL; } return filter; }
/* * If type==0, only last line of output is returned (exec) * If type==1, all lines will be printed and last lined returned (system) * If type==2, all lines will be saved to given array (exec with &$array) * If type==3, output will be printed binary, no lines will be saved or returned (passthru) * */ int php_Exec(int type, char *cmd, pval *array, pval *return_value) { FILE *fp; char *buf, *tmp=NULL; int buflen = 0; int t, l, output=1; int overflow_limit, lcmd, ldir; int rsrc_id; char *b, *c, *d=NULL; #if PHP_SIGCHILD void (*sig_handler)(); #endif PLS_FETCH(); FLS_FETCH(); buf = (char*) emalloc(EXEC_INPUT_BUF); if (!buf) { php_error(E_WARNING, "Unable to emalloc %d bytes for exec buffer", EXEC_INPUT_BUF); return -1; } buflen = EXEC_INPUT_BUF; if (PG(safe_mode)) { lcmd = strlen(cmd); ldir = strlen(PG(safe_mode_exec_dir)); l = lcmd + ldir + 2; overflow_limit = l; c = strchr(cmd, ' '); if (c) *c = '\0'; if (strstr(cmd, "..")) { php_error(E_WARNING, "No '..' components allowed in path"); efree(buf); return -1; } d = emalloc(l); strcpy(d, PG(safe_mode_exec_dir)); overflow_limit -= ldir; b = strrchr(cmd, PHP_DIR_SEPARATOR); if (b) { strcat(d, b); overflow_limit -= strlen(b); } else { strcat(d, "/"); strcat(d, cmd); overflow_limit-=(strlen(cmd)+1); } if (c) { *c = ' '; strncat(d, c, overflow_limit); } tmp = php_escape_shell_cmd(d); efree(d); d = tmp; #if PHP_SIGCHILD sig_handler = signal (SIGCHLD, SIG_DFL); #endif #ifdef PHP_WIN32 fp = VCWD_POPEN(d, "rb"); #else fp = VCWD_POPEN(d, "r"); #endif if (!fp) { php_error(E_WARNING, "Unable to fork [%s]", d); efree(d); efree(buf); #if PHP_SIGCHILD signal (SIGCHLD, sig_handler); #endif return -1; } } else { /* not safe_mode */ #if PHP_SIGCHILD sig_handler = signal (SIGCHLD, SIG_DFL); #endif #ifdef PHP_WIN32 fp = VCWD_POPEN(cmd, "rb"); #else fp = VCWD_POPEN(cmd, "r"); #endif if (!fp) { php_error(E_WARNING, "Unable to fork [%s]", cmd); efree(buf); #if PHP_SIGCHILD signal (SIGCHLD, sig_handler); #endif return -1; } } buf[0] = '\0'; if (type==2) { if (Z_TYPE_P(array) != IS_ARRAY) { pval_destructor(array); array_init(array); } } /* we register the resource so that case of an aborted connection the * fd gets pclosed */ rsrc_id = ZEND_REGISTER_RESOURCE(NULL, fp, php_file_le_popen()); if (type != 3) { l=0; while ( !feof(fp) || l != 0 ) { l = 0; /* Read a line or fill the buffer, whichever comes first */ do { if ( buflen <= (l+1) ) { buf = erealloc(buf, buflen + EXEC_INPUT_BUF); if ( buf == NULL ) { php_error(E_WARNING, "Unable to erealloc %d bytes for exec buffer", buflen + EXEC_INPUT_BUF); #if PHP_SIGCHILD signal (SIGCHLD, sig_handler); #endif return -1; } buflen += EXEC_INPUT_BUF; } if ( fgets(&(buf[l]), buflen - l, fp) == NULL ) { /* eof */ break; } l += strlen(&(buf[l])); } while ( (l > 0) && (buf[l-1] != '\n') ); if ( feof(fp) && (l == 0) ) { break; } if (type == 1) { if (output) PUTS(buf); sapi_flush(); } else if (type == 2) { /* strip trailing whitespaces */ l = strlen(buf); t = l; while (l-- && isspace((int)buf[l])); if (l < t) { buf[l + 1] = '\0'; } add_next_index_string(array, buf, 1); } } /* strip trailing spaces */ l = strlen(buf); t = l; while (l && isspace((int)buf[l - 1])) { l--; } if (l < t) buf[l] = '\0'; /* Return last line from the shell command */ if (PG(magic_quotes_runtime)) { int len; tmp = php_addslashes(buf, 0, &len, 0); RETVAL_STRINGL(tmp,len,0); } else { RETVAL_STRINGL(buf,l,1); } } else { int b, i; while ((b = fread(buf, 1, buflen, fp)) > 0) { for (i = 0; i < b; i++) if (output) (void)PUTC(buf[i]); } } /* the zend_list_delete will pclose our popen'ed process */ zend_list_delete(rsrc_id); #if HAVE_SYS_WAIT_H if (WIFEXITED(FG(pclose_ret))) { FG(pclose_ret) = WEXITSTATUS(FG(pclose_ret)); } #endif #if PHP_SIGCHILD signal (SIGCHLD, sig_handler); #endif if (d) { efree(d); } efree(buf); return FG(pclose_ret); }
/* ArchiveWriter::finish {{{ * */ ZEND_METHOD(ArchiveWriter, finish) { zval *this = getThis(); int resource_id; HashPosition pos; archive_file_t *arch; archive_entry_t **entry; int result, error_num; const char *error_string; mode_t mode; php_stream *stream; zend_error_handling error_handling; zend_replace_error_handling(EH_THROW, ce_ArchiveException, &error_handling TSRMLS_CC); if (!_archive_get_fd(this, &arch TSRMLS_CC)) { zend_restore_error_handling(&error_handling TSRMLS_CC); return; } if (zend_hash_sort(arch->entries, zend_qsort, _archive_pathname_compare, 0 TSRMLS_CC) == FAILURE) { RETURN_FALSE; } zend_hash_internal_pointer_reset_ex(arch->entries, &pos); while (zend_hash_get_current_data_ex(arch->entries, (void **)&entry, &pos) == SUCCESS) { mode = archive_entry_mode((*entry)->entry); if (S_ISREG(mode) && archive_entry_size((*entry)->entry) > 0) { if ((stream = php_stream_open_wrapper_ex((*entry)->filename, "r", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, NULL))) { char buf[PHP_ARCHIVE_BUF_LEN]; int header_written=0; int read_bytes; while ((read_bytes = php_stream_read(stream, buf, PHP_ARCHIVE_BUF_LEN))) { if (!header_written) { /* write header only after the first successful read */ result = archive_write_header(arch->arch, (*entry)->entry); if (result == ARCHIVE_FATAL) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to write entry header for file %s: fatal error", (*entry)->filename); zend_restore_error_handling(&error_handling TSRMLS_CC); return; } header_written = 1; } result = archive_write_data(arch->arch, buf, read_bytes); if (result <= 0) { error_num = archive_errno(arch->arch); error_string = archive_error_string(arch->arch); if (error_num && error_string) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to write file %s to archive: error #%d, %s", (*entry)->filename, error_num, error_string); } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to write file %s: unknown error %d", (*entry)->filename, result); } php_stream_close(stream); zend_restore_error_handling(&error_handling TSRMLS_CC); return; } } php_stream_close(stream); } } else { result = archive_write_header(arch->arch, (*entry)->entry); if (result == ARCHIVE_FATAL) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to write entry header for file %s: fatal error", (*entry)->filename); zend_restore_error_handling(&error_handling TSRMLS_CC); return; } } zend_hash_move_forward_ex(arch->entries, &pos); } if ((resource_id = _archive_get_rsrc_id(this TSRMLS_CC))) { add_property_resource(this, "fd", 0); zend_list_delete(resource_id); zend_restore_error_handling(&error_handling TSRMLS_CC); RETURN_TRUE; } php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to finish writing of archive file"); zend_restore_error_handling(&error_handling TSRMLS_CC); }
static void birdstep_del_result(HashTable *list,int ind) { zend_list_delete(ind); }
static void _php_do_opendir(INTERNAL_FUNCTION_PARAMETERS, int createobject) { pval **arg; php_dir *dirp; DIRLS_FETCH(); if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_string_ex(arg); if (php_check_open_basedir((*arg)->value.str.val)) { RETURN_FALSE; } dirp = emalloc(sizeof(php_dir)); dirp->dir = VCWD_OPENDIR((*arg)->value.str.val); #ifdef PHP_WIN32 if (!dirp->dir || dirp->dir->finished) { if (dirp->dir) { closedir(dirp->dir); } #else if (!dirp->dir) { #endif efree(dirp); php_error(E_WARNING, "OpenDir: %s (errno %d)", strerror(errno), errno); RETURN_FALSE; } dirp->id = zend_list_insert(dirp,le_dirp); php_set_default_dir(dirp->id DIRLS_CC); if (createobject) { object_init_ex(return_value, dir_class_entry_ptr); add_property_stringl(return_value, "path", (*arg)->value.str.val, (*arg)->value.str.len, 1); add_property_resource(return_value, "handle", dirp->id); zend_list_addref(dirp->id); } else { RETURN_RESOURCE(dirp->id); } } /* }}} */ /* {{{ proto int opendir(string path) Open a directory and return a dir_handle */ PHP_FUNCTION(opendir) { _php_do_opendir(INTERNAL_FUNCTION_PARAM_PASSTHRU,0); } /* }}} */ /* {{{ proto class dir(string directory) Directory class with properties, handle and class and methods read, rewind and close */ PHP_FUNCTION(getdir) { _php_do_opendir(INTERNAL_FUNCTION_PARAM_PASSTHRU,1); } /* }}} */ /* {{{ proto void closedir([int dir_handle]) Close directory connection identified by the dir_handle */ PHP_FUNCTION(closedir) { pval **id, **tmp, *myself; php_dir *dirp; DIRLS_FETCH(); FETCH_DIRP(); zend_list_delete(dirp->id); if (dirp->id == DIRG(default_dir)) { php_set_default_dir(-1 DIRLS_CC); } } /* }}} */ #if defined(HAVE_CHROOT) && !defined(ZTS) /* {{{ proto int chroot(string directory) Change root directory */ PHP_FUNCTION(chroot) { pval **arg; int ret; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_string_ex(arg); ret = chroot((*arg)->value.str.val); if (ret != 0) { php_error(E_WARNING, "chroot: %s (errno %d)", strerror(errno), errno); RETURN_FALSE; } ret = chdir("/"); if (ret != 0) { php_error(E_WARNING, "chdir: %s (errno %d)", strerror(errno), errno); RETURN_FALSE; } RETURN_TRUE; } /* }}} */ #endif /* {{{ proto int chdir(string directory) Change the current directory */ PHP_FUNCTION(chdir) { pval **arg; int ret; PLS_FETCH(); if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_string_ex(arg); if (PG(safe_mode) && !php_checkuid((*arg)->value.str.val, NULL, CHECKUID_ALLOW_ONLY_DIR)) { RETURN_FALSE; } ret = VCWD_CHDIR((*arg)->value.str.val); if (ret != 0) { php_error(E_WARNING, "ChDir: %s (errno %d)", strerror(errno), errno); RETURN_FALSE; } RETURN_TRUE; } /* }}} */ /* {{{ proto string getcwd(void) Gets the current directory */ PHP_FUNCTION(getcwd) { char path[MAXPATHLEN]; char *ret=NULL; if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } #if HAVE_GETCWD ret = VCWD_GETCWD(path, MAXPATHLEN); #elif HAVE_GETWD ret = VCWD_GETWD(path); /* * #warning is not ANSI C * #else * #warning no proper getcwd support for your site */ #endif if (ret) { RETURN_STRING(path,1); } else { RETURN_FALSE; } } /* }}} */ /* {{{ proto void rewinddir([int dir_handle]) Rewind dir_handle back to the start */ PHP_FUNCTION(rewinddir) { pval **id, **tmp, *myself; php_dir *dirp; DIRLS_FETCH(); FETCH_DIRP(); rewinddir(dirp->dir); } /* }}} */ /* {{{ proto string readdir([int dir_handle]) Read directory entry from dir_handle */ PHP_NAMED_FUNCTION(php_if_readdir) { pval **id, **tmp, *myself; php_dir *dirp; char entry[sizeof(struct dirent)+MAXPATHLEN]; struct dirent *result = (struct dirent *)&entry; /* patch for libc5 readdir problems */ DIRLS_FETCH(); FETCH_DIRP(); if (php_readdir_r(dirp->dir, (struct dirent *) entry, &result) == 0 && result) { RETURN_STRINGL(result->d_name, strlen(result->d_name), 1); } RETURN_FALSE; }