On Tue, 2007-06-19 at 10:58 +0530, anand chugh wrote:
> Hi
> 
> I am having code like this:
> 
>    rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
>    if( rc!=SQLITE_OK ){
>      return rc;
>    }
>    sqlite3_bind_text(pStmt, 1, zKey, -1, SQLITE_STATIC);
>    sqlite3_bind_blob(pStmt, 2, zBlob, nBlob, SQLITE_STATIC);
> 
>    while( sqlite3_step(pStmt)==SQLITE_ROW )
>  {
>      *pnBlob = sqlite3_column_bytes(pStmt, 0);
>      *pzBlob = (unsigned char *)malloc(*pnBlob);
>      memcpy(*pzBlob, sqlite3_column_blob(pStmt, 0), *pnBlob);
>    }
> 
>   sqlite3_finalize(pStmt);
> 
> My question here is do I need to do sqlite3_finalize(pStmt); after
> every sqlite3_step() to free all memory allocated by
> sqlite3_step().

No. Exactly one sqlite3_finalize() for each sqlite3_prepare(). In
this respect the code above is fine.

It's not SQLite related, but if the SQL statement returns more 
than one row, the malloc() in the while loop will cause a memory 
leak.

Dan.

> Does calling finalize at end will free all memory
> allocated by all steps statements?
> 
>  Example shown http://www.sqlite.org/cvstrac/wiki?p=BlobExample does
> same , it calls finalize after  every step.
> 
> My Program shows some Memory Leaks(Virtual Bytes).
> 
> Please clarify.
> 
> Anand
> 
> -----------------------------------------------------------------------------
> To unsubscribe, send email to [EMAIL PROTECTED]
> -----------------------------------------------------------------------------
> 


-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to