1
0
Fork 0
mirror of https://github.com/DBD-SQLite/DBD-SQLite synced 2025-06-07 14:19:10 -04:00

DBD-SQLite: don't cache a statement if it is not properly prepared to avoid memory leakage

This commit is contained in:
Kenichi Ishigaki 2009-07-16 17:27:56 +00:00
parent d017f3ce67
commit 1bb88bfae0

View file

@ -272,7 +272,6 @@ sqlite_st_prepare (SV *sth, imp_sth_t *imp_sth,
imp_sth->retval = SQLITE_OK;
imp_sth->params = newAV();
imp_sth->col_types = newAV();
imp_sth->statement = savepv(statement); /* store the query for later re-use if required */
if ((retval = sqlite3_prepare_v2(imp_dbh->db, statement, -1, &(imp_sth->stmt), &extra))
!= SQLITE_OK)
@ -284,6 +283,10 @@ sqlite_st_prepare (SV *sth, imp_sth_t *imp_sth,
return FALSE; /* -> undef in lib/DBD/SQLite.pm */
}
/* store the query for later re-use if required */
/* but only when the query is properly prepared */
imp_sth->statement = savepv(statement);
DBIc_NUM_PARAMS(imp_sth) = sqlite3_bind_parameter_count(imp_sth->stmt);
DBIc_NUM_FIELDS(imp_sth) = sqlite3_column_count(imp_sth->stmt);
DBIc_IMPSET_on(imp_sth);