diff options
author | drh <drh@noemail.net> | 2020-10-17 22:13:16 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2020-10-17 22:13:16 +0000 |
commit | ff01ee34c9298f6461e1b282eea2178c08b7d16a (patch) | |
tree | 8f207682f45bca46ba255c543c6d9f16f7f60489 /src/memdb.c | |
parent | e93986a93b07e63ae5c92e1c9e9b193c1484531d (diff) | |
download | sqlite-ff01ee34c9298f6461e1b282eea2178c08b7d16a.tar.gz sqlite-ff01ee34c9298f6461e1b282eea2178c08b7d16a.zip |
Fix the SQLITE_DESERIALIZE_FREEONCLOSE flag so that it works as it is
documented to work.
See [forum:/forumpost/ba1dff667a|forum post ba1dff667a]
FossilOrigin-Name: d6fac8a1d3efeb2c4f03dae437b5b314765c93770a70603803a8039291dbcabb
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; } |