summaryrefslogtreecommitdiff
path: root/ext/sqlite/sqlite.c
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2003-12-28 16:26:04 +0000
committerMarcus Boerger <helly@php.net>2003-12-28 16:26:04 +0000
commit1a48fd929dc9ab010879d8a66cc4f8eb5d3af821 (patch)
treea3284fa2e4b0fc25052042ed8c2f51d2db3a5527 /ext/sqlite/sqlite.c
parent2a6ec5ccb48f40abce1fba77736ee6ba8c9d9018 (diff)
downloadphp-git-1a48fd929dc9ab010879d8a66cc4f8eb5d3af821.tar.gz
Fix a memleak
Improve error messages
Diffstat (limited to 'ext/sqlite/sqlite.c')
-rw-r--r--ext/sqlite/sqlite.c50
1 files changed, 32 insertions, 18 deletions
diff --git a/ext/sqlite/sqlite.c b/ext/sqlite/sqlite.c
index 2a4a095f7d..707c282172 100644
--- a/ext/sqlite/sqlite.c
+++ b/ext/sqlite/sqlite.c
@@ -415,14 +415,13 @@ static void php_sqlite_generic_function_callback(sqlite_func *func, int argc, co
ZVAL_STRING(&funcname, (char*)argv[0], 1);
if (!zend_make_callable(&funcname, &callable TSRMLS_CC)) {
- spprintf(&errbuf, 0, "function `%s' is not funcname", callable);
+ spprintf(&errbuf, 0, "function `%s' is not a function name", callable);
sqlite_set_result_error(func, errbuf, -1);
efree(errbuf);
efree(callable);
zval_dtor(&funcname);
return;
}
- efree(callable);
if (argc > 1) {
zargs = (zval ***)safe_emalloc((argc - 1), sizeof(zval **), 0);
@@ -441,6 +440,7 @@ static void php_sqlite_generic_function_callback(sqlite_func *func, int argc, co
argc-1,
zargs,
0, NULL TSRMLS_CC);
+
zval_dtor(&funcname);
if (res == SUCCESS) {
@@ -464,9 +464,14 @@ static void php_sqlite_generic_function_callback(sqlite_func *func, int argc, co
}
}
} else {
- sqlite_set_result_error(func, "call_user_function_ex failed", -1);
+ char *errbuf;
+ spprintf(&errbuf, 0, "call_user_function_ex failed for function %s()", callable);
+ sqlite_set_result_error(func, errbuf, -1);
+ efree(errbuf);
}
+ efree(callable);
+
if (retval) {
zval_ptr_dtor(&retval);
}
@@ -1451,9 +1456,9 @@ next_row:
/* }}} */
/* {{{ sqlite_query */
-void sqlite_query(zval *object, struct php_sqlite_db *db, char *sql, long sql_len, int mode, int buffered, zval *return_value, struct php_sqlite_result *rres TSRMLS_DC)
+void sqlite_query(zval *object, struct php_sqlite_db *db, char *sql, long sql_len, int mode, int buffered, zval *return_value, struct php_sqlite_result **prres TSRMLS_DC)
{
- struct php_sqlite_result res;
+ struct php_sqlite_result res, *rres;
int ret;
char *errtext = NULL;
const char *tail;
@@ -1475,17 +1480,22 @@ void sqlite_query(zval *object, struct php_sqlite_db *db, char *sql, long sql_le
}
}
- if (!rres) {
- rres = (struct php_sqlite_result*)emalloc(sizeof(*rres));
+ if (!prres) {
+ rres = NULL;
+ prres = &rres;
}
- memcpy(rres, &res, sizeof(*rres));
- rres->db = db;
+ if (!*prres) {
+ *prres = (struct php_sqlite_result*)emalloc(sizeof(**prres));
+ }
+ memcpy(*prres, &res, sizeof(**prres));
+ (*prres)->db = db;
zend_list_addref(db->rsrc_id);
/* now the result set is ready for stepping: get first row */
- if (php_sqlite_fetch(rres TSRMLS_CC) != SQLITE_OK) {
- real_result_dtor(rres TSRMLS_CC);
+ if (php_sqlite_fetch((*prres) TSRMLS_CC) != SQLITE_OK) {
+ real_result_dtor((*prres) TSRMLS_CC);
+ *prres = NULL;
if (return_value) {
RETURN_FALSE;
} else {
@@ -1493,7 +1503,7 @@ void sqlite_query(zval *object, struct php_sqlite_db *db, char *sql, long sql_le
}
}
- rres->curr_row = 0;
+ (*prres)->curr_row = 0;
if (object) {
sqlite_object *obj;
@@ -1504,9 +1514,9 @@ void sqlite_query(zval *object, struct php_sqlite_db *db, char *sql, long sql_le
}
obj = (sqlite_object *) zend_object_store_get_object(return_value TSRMLS_CC);
obj->type = is_result;
- obj->u.res = rres;
+ obj->u.res = (*prres);
} else if (return_value) {
- ZEND_REGISTER_RESOURCE(object ? NULL : return_value, rres, le_sqlite_result);
+ ZEND_REGISTER_RESOURCE(object ? NULL : return_value, (*prres), le_sqlite_result);
}
}
/* }}} */
@@ -2015,9 +2025,11 @@ PHP_FUNCTION(sqlite_array_query)
}
rres = (struct php_sqlite_result *)emalloc(sizeof(*rres));
- sqlite_query(NULL, db, sql, sql_len, mode, 0, NULL, rres TSRMLS_CC);
+ sqlite_query(NULL, db, sql, sql_len, mode, 0, NULL, &rres TSRMLS_CC);
if (db->last_err_code != SQLITE_OK) {
- efree(rres);
+ if (rres) {
+ efree(rres);
+ }
RETURN_FALSE;
}
@@ -2127,9 +2139,11 @@ PHP_FUNCTION(sqlite_single_query)
}
rres = (struct php_sqlite_result *)emalloc(sizeof(*rres));
- sqlite_query(NULL, db, sql, sql_len, PHPSQLITE_NUM, 0, NULL, rres TSRMLS_CC);
+ sqlite_query(NULL, db, sql, sql_len, PHPSQLITE_NUM, 0, NULL, &rres TSRMLS_CC);
if (db->last_err_code != SQLITE_OK) {
- efree(rres);
+ if (rres) {
+ efree(rres);
+ }
RETURN_FALSE;
}