diff options
Diffstat (limited to 'src/memdb.c')
-rw-r--r-- | src/memdb.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/memdb.c b/src/memdb.c index dc969a47e..d07023dba 100644 --- a/src/memdb.c +++ b/src/memdb.c @@ -126,11 +126,14 @@ static const sqlite3_io_methods memdb_io_methods = { ** Close an memdb-file. ** ** The pData pointer is owned by the application, so there is nothing -** to free. +** to free. Unless the SQLITE_DESERIALIZE_FREEONCLOSE flag is set, +** in which case we own the pData pointer and need to free it. */ static int memdbClose(sqlite3_file *pFile){ MemFile *p = (MemFile *)pFile; - if( p->mFlags & SQLITE_DESERIALIZE_FREEONCLOSE ) sqlite3_free(p->aData); + if( p->mFlags & SQLITE_DESERIALIZE_FREEONCLOSE ){ + sqlite3_free(p->aData); + } return SQLITE_OK; } @@ -589,6 +592,7 @@ int sqlite3_deserialize( rc = SQLITE_ERROR; }else{ p->aData = pData; + pData = 0; p->sz = szDb; p->szAlloc = szBuf; p->szMax = szBuf; @@ -601,6 +605,9 @@ int sqlite3_deserialize( end_deserialize: sqlite3_finalize(pStmt); + if( pData && (mFlags & SQLITE_DESERIALIZE_FREEONCLOSE)!=0 ){ + sqlite3_free(pData); + } sqlite3_mutex_leave(db->mutex); return rc; } |