On Tue, May 15, 2012 at 10:34 PM, Jay A. Kreibich <j...@kreibi.ch> wrote:

> On Tue, May 15, 2012 at 10:17:41PM +0300, Baruch Burstein scratched on
> the wall:
> > Which of the following should I be running right before calling
> > sqlite3_close?
> >
> > while(stmt = sqlite3_next_stmt(db, stmt))
> >         sqlite3_finalize(stmt);
> >
> > while(stmt = sqlite3_next_stmt(db, NULL))
> >         sqlite3_finalize(stmt);
> >
> > I am not sure which will have the desired effect.
>
>   The second, since "stmt" will be an invalid pointer by the time
>  the loop comes around and hits sqlite3_next_stmt() again.
>
>  Ideally, however, your application should manage its own statements
>  correctly.  This type of brute-force clean-up can act as a safety net,
>  but it can also leave dangling pointers elsewhere in the code.
>  Something in your code must know about those statements... and if
>  not, then you're leaking memory, which is just as bad.
>

I am aware of this. However, I am working on a  C++ wrapper for sqlite. It
is the wrapper's user's responsibility to make sure no statement objects
still exist before the database object gets destroyed. This is just a
precaution.

-- 
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.  - Rich Cook
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to