Skip to content

Commit

Permalink
MFB:
Browse files Browse the repository at this point in the history
 Fixed bug #46042 (memory leaks with reflection of mb_convert_encoding())
 Fixed bug #46110 (XMLWriter - openmemory() and openuri() leak memory on
  multiple calls).
 Fixed bug #46206 (pg_query_params/pg_execute convert passed values to
  strings).
  • Loading branch information
Ilia Alshanetsky committed Oct 7, 2008
1 parent 73042af commit bef0a45
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 53 deletions.
5 changes: 5 additions & 0 deletions NEWS
Expand Up @@ -20,11 +20,15 @@ PHP NEWS
(Christian Seiler)
- Fixed bug #46215 (json_encode mutates its parameter and has some
class-specific state). (Felipe)
- Fixed bug #46206 (pg_query_params/pg_execute convert passed values to
strings). (Ilia)
- Fixed bug #46191 (BC break: DOMDocument saveXML() doesn't accept null). (Rob)
- Fixed bug #46164 (stream_filter_remove() closes the stream). (Arnaud)
- Fixed bug #46157 (PDOStatement::fetchObject prototype error). (Felipe)
- Fixed bug #46147 (after stream seek, appending stream filter reads
incorrect data). (Greg)
- Fixed bug #46110 (XMLWriter - openmemory() and openuri() leak memory on
multiple calls). (Ilia)
- Fixed bug #46088 (RegexIterator::accept - segfault). (Felipe)
- Fixed bug #46059 (Compile failure under IRIX 6.5.30 building posix.c).
(Arnaud)
Expand Down Expand Up @@ -77,6 +81,7 @@ PHP NEWS
- Fixed bug #45405 (snmp extension memory leak). (Federico Cuello, Rodrigo
Campos)
- Fixed bug #45392 (ob_start()/ob_end_clean() and memory_limit). (Arnaud)
- Fixed bug #45382 (timeout bug in stream_socket_enable_crypto). (Ilia)
- Fixed bug #45373 (php crash on query with errors in params). (Felipe)
- Fixed bug #45352 (Segmentation fault because of tick function on second
request). (Dmitry)
Expand Down
2 changes: 1 addition & 1 deletion ext/openssl/xp_ssl.c
Expand Up @@ -417,7 +417,7 @@ static inline int php_openssl_enable_crypto(php_stream *stream,
n = SSL_connect(sslsock->ssl_handle);
gettimeofday(&tve, &tz);

timeout -= (tve.tv_sec + tve.tv_usec / 1000000) - (tvs.tv_sec + tvs.tv_usec / 1000000);
timeout -= (tve.tv_sec + (float) tve.tv_usec / 1000000) - (tvs.tv_sec + (float) tvs.tv_usec / 1000000);
if (timeout < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "SSL: connection timeout");
return -1;
Expand Down
107 changes: 55 additions & 52 deletions ext/pgsql/pgsql.c
Expand Up @@ -1199,6 +1199,10 @@ PHP_FUNCTION(pg_query)
static void _php_pgsql_free_params(char **params, int num_params)
{
if (num_params > 0) {
int i;
for (i = 0; i < num_params; i++) {
efree(params[i]);
}
efree(params);
}
}
Expand All @@ -1216,7 +1220,6 @@ PHP_FUNCTION(pg_query_params)
int leftover = 0;
int num_params = 0;
char **params = NULL;
unsigned char otype;
PGconn *pgsql;
PGresult *pgsql_result;
ExecStatusType status;
Expand Down Expand Up @@ -1276,19 +1279,20 @@ PHP_FUNCTION(pg_query_params)
RETURN_FALSE;
}

otype = (*tmp)->type;
convert_to_string_ex(tmp);
if (Z_TYPE_PP(tmp) != IS_STRING) {
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter");
_php_pgsql_free_params(params, num_params);
RETURN_FALSE;
}

if (otype == IS_NULL) {
if (Z_TYPE_PP(tmp) == IS_NULL) {
params[i] = NULL;
}
else {
params[i] = Z_STRVAL_PP(tmp);
} else {
zval tmp_val = **tmp;
zval_copy_ctor(&tmp_val);
convert_to_string(&tmp_val);
if (Z_TYPE(tmp_val) != IS_STRING) {
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter");
zval_dtor(&tmp_val);
_php_pgsql_free_params(params, num_params);
RETURN_FALSE;
}
params[i] = estrndup(Z_STRVAL(tmp_val), Z_STRLEN(tmp_val));
zval_dtor(&tmp_val);
}

zend_hash_move_forward(Z_ARRVAL_PP(pv_param_arr));
Expand Down Expand Up @@ -1439,7 +1443,6 @@ PHP_FUNCTION(pg_execute)
int leftover = 0;
int num_params = 0;
char **params = NULL;
unsigned char otype;
PGconn *pgsql;
PGresult *pgsql_result;
ExecStatusType status;
Expand Down Expand Up @@ -1500,19 +1503,20 @@ PHP_FUNCTION(pg_execute)
RETURN_FALSE;
}

otype = (*tmp)->type;
SEPARATE_ZVAL(tmp);
convert_to_string_ex(tmp);
if (Z_TYPE_PP(tmp) != IS_STRING) {
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter");
_php_pgsql_free_params(params, num_params);
RETURN_FALSE;
}

if (otype == IS_NULL) {
if (Z_TYPE_PP(tmp) == IS_NULL) {
params[i] = NULL;
} else {
params[i] = Z_STRVAL_PP(tmp);
zval tmp_val = **tmp;
zval_copy_ctor(&tmp_val);
convert_to_string(&tmp_val);
if (Z_TYPE(tmp_val) != IS_STRING) {
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter");
zval_dtor(&tmp_val);
_php_pgsql_free_params(params, num_params);
RETURN_FALSE;
}
params[i] = estrndup(Z_STRVAL(tmp_val), Z_STRLEN(tmp_val));
zval_dtor(&tmp_val);
}

zend_hash_move_forward(Z_ARRVAL_PP(pv_param_arr));
Expand Down Expand Up @@ -4048,7 +4052,6 @@ PHP_FUNCTION(pg_send_query_params)
zval **pv_param_arr, **tmp;
int num_params = 0;
char **params = NULL;
unsigned char otype;
zval **query;
int id = -1;
PGconn *pgsql;
Expand Down Expand Up @@ -4097,20 +4100,20 @@ PHP_FUNCTION(pg_send_query_params)
RETURN_FALSE;
}

otype = (*tmp)->type;
SEPARATE_ZVAL(tmp);
convert_to_string_ex(tmp);
if (Z_TYPE_PP(tmp) != IS_STRING) {
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter");
_php_pgsql_free_params(params, num_params);
RETURN_FALSE;
}

if (otype == IS_NULL) {
if (Z_TYPE_PP(tmp) == IS_NULL) {
params[i] = NULL;
}
else {
params[i] = Z_STRVAL_PP(tmp);
} else {
zval tmp_val = **tmp;
zval_copy_ctor(&tmp_val);
convert_to_string(&tmp_val);
if (Z_TYPE(tmp_val) != IS_STRING) {
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter");
zval_dtor(&tmp_val);
_php_pgsql_free_params(params, num_params);
RETURN_FALSE;
}
params[i] = estrndup(Z_STRVAL(tmp_val), Z_STRLEN(tmp_val));
zval_dtor(&tmp_val);
}

zend_hash_move_forward(Z_ARRVAL_PP(pv_param_arr));
Expand Down Expand Up @@ -4194,7 +4197,6 @@ PHP_FUNCTION(pg_send_execute)
zval **pv_param_arr, **tmp;
int num_params = 0;
char **params = NULL;
unsigned char otype;
zval **stmtname;
int id = -1;
PGconn *pgsql;
Expand Down Expand Up @@ -4241,19 +4243,20 @@ PHP_FUNCTION(pg_send_execute)
RETURN_FALSE;
}

otype = (*tmp)->type;
convert_to_string(*tmp);
if (Z_TYPE_PP(tmp) != IS_STRING) {
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter");
_php_pgsql_free_params(params, num_params);
RETURN_FALSE;
}

if (otype == IS_NULL) {
if (Z_TYPE_PP(tmp) == IS_NULL) {
params[i] = NULL;
}
else {
params[i] = Z_STRVAL_PP(tmp);
} else {
zval tmp_val = **tmp;
zval_copy_ctor(&tmp_val);
convert_to_string(&tmp_val);
if (Z_TYPE(tmp_val) != IS_STRING) {
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter");
zval_dtor(&tmp_val);
_php_pgsql_free_params(params, num_params);
RETURN_FALSE;
}
params[i] = estrndup(Z_STRVAL(tmp_val), Z_STRLEN(tmp_val));
zval_dtor(&tmp_val);
}

zend_hash_move_forward(Z_ARRVAL_PP(pv_param_arr));
Expand Down
6 changes: 6 additions & 0 deletions ext/xmlwriter/php_xmlwriter.c
Expand Up @@ -1483,6 +1483,9 @@ static PHP_FUNCTION(xmlwriter_open_uri)
intern->uri_output = out_buffer;
#else
if (this) {
if (ze_obj->xmlwriter_ptr) {
xmlwriter_free_resource_ptr(ze_obj->xmlwriter_ptr TSRMLS_CC);
}
ze_obj->xmlwriter_ptr = intern;
RETURN_TRUE;
} else
Expand Down Expand Up @@ -1533,6 +1536,9 @@ static PHP_FUNCTION(xmlwriter_open_memory)
intern->uri_output = NULL;
#else
if (this) {
if (ze_obj->xmlwriter_ptr) {
xmlwriter_free_resource_ptr(ze_obj->xmlwriter_ptr TSRMLS_CC);
}
ze_obj->xmlwriter_ptr = intern;
RETURN_TRUE;
} else
Expand Down

0 comments on commit bef0a45

Please sign in to comment.