Patch pgsql-fixed.diff for PostgreSQL related Bug #52389
Patch version 2010-10-18 10:53 UTC
Return to Bug #52389 |
Download this patch
Patch Revisions:
Developer: jaromir.dolecek@skype.net
$NetBSD$
--- ext/pgsql/pgsql.c.orig 2010-10-18 10:25:46.000000000 +0000
+++ ext/pgsql/pgsql.c
@@ -728,9 +728,10 @@ ZEND_GET_MODULE(pgsql)
static int le_link, le_plink, le_result, le_lofp, le_string;
/* {{{ _php_pgsql_trim_message */
-static char * _php_pgsql_trim_message(const char *message, int *len)
+static char * _php_pgsql_trim_message(const char *message, int *len, int persistent)
{
register int i = strlen(message)-1;
+ char *ret_msg;
if (i>1 && (message[i-1] == '\r' || message[i-1] == '\n') && message[i] == '.') {
--i;
@@ -742,21 +743,29 @@ static char * _php_pgsql_trim_message(co
if (len) {
*len = i;
}
- return estrndup(message, i);
+
+ if (persistent) {
+ char *ret_msg = (char *)pemalloc((i+1)*sizeof(char), 1);
+ memcpy(ret_msg, message, i*sizeof(char));
+ ret_msg[i] = '\0';
+ } else {
+ ret_msg = estrndup(message, i);
+ }
+ return ret_msg;
}
/* }}} */
/* {{{ _php_pgsql_trim_result */
static inline char * _php_pgsql_trim_result(PGconn * pgsql, char **buf)
{
- return *buf = _php_pgsql_trim_message(PQerrorMessage(pgsql), NULL);
+ return *buf = _php_pgsql_trim_message(PQerrorMessage(pgsql), NULL, 0);
}
/* }}} */
#define PQErrorMessageTrim(pgsql, buf) _php_pgsql_trim_result(pgsql, buf)
#define PHP_PQ_ERROR(text, pgsql) { \
- char *msgbuf = _php_pgsql_trim_message(PQerrorMessage(pgsql), NULL); \
+ char *msgbuf = _php_pgsql_trim_message(PQerrorMessage(pgsql), NULL, 0); \
php_error_docref(NULL TSRMLS_CC, E_WARNING, text, msgbuf); \
efree(msgbuf); \
} \
@@ -775,6 +784,13 @@ static void php_pgsql_set_default_link(i
}
/* }}} */
+/* {{{ _clean_pgsql_link_notice
+*/
+static void _clean_pgsql_notice(PGconn *link)
+{
+ zend_hash_index_del(&PGG(notices), (ulong)link);
+}
+
/* {{{ _close_pgsql_link
*/
static void _close_pgsql_link(zend_rsrc_list_entry *rsrc TSRMLS_DC)
@@ -787,6 +803,7 @@ static void _close_pgsql_link(zend_rsrc_
}
PQfinish(link);
PGG(num_links)--;
+ _clean_pgsql_notice(link);
}
/* }}} */
@@ -803,6 +820,7 @@ static void _close_pgsql_plink(zend_rsrc
PQfinish(link);
PGG(num_persistent)--;
PGG(num_links)--;
+ _clean_pgsql_notice(link);
}
/* }}} */
@@ -814,8 +832,8 @@ static void _php_pgsql_notice_handler(vo
TSRMLS_FETCH();
if (! PGG(ignore_notices)) {
- notice = (php_pgsql_notice *)emalloc(sizeof(php_pgsql_notice));
- notice->message = _php_pgsql_trim_message(message, ¬ice->len);
+ notice = (php_pgsql_notice *)pemalloc(sizeof(php_pgsql_notice), 1);
+ notice->message = _php_pgsql_trim_message(message, ¬ice->len, 1);
if (PGG(log_notices)) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s", notice->message);
}
@@ -832,8 +850,8 @@ static void _php_pgsql_notice_ptr_dtor(v
{
php_pgsql_notice *notice = (php_pgsql_notice *)*ptr;
if (notice) {
- efree(notice->message);
- efree(notice);
+ pefree(notice->message, 1);
+ pefree(notice, 1);
notice = NULL;
}
}
@@ -876,6 +894,7 @@ static int _rollback_transactions(zend_r
PQclear(res);
PGG(ignore_notices) = orig;
}
+ _clean_pgsql_notice(link);
return 0;
}
|