From: drh Date: Fri, 16 Sep 2005 00:27:01 +0000 (+0000) Subject: Fix a memory leak: a failure to deallocate the P3 parameter on a call X-Git-Tag: version-3.6.10~3464 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b38ad9991c3a58de6e246362b832368b6d2826ff;p=thirdparty%2Fsqlite.git Fix a memory leak: a failure to deallocate the P3 parameter on a call to sqlite3VdbeChangeP3. (CVS 2695) FossilOrigin-Name: 714254cbc12564d44548707043fdcdffb17e4fde --- diff --git a/manifest b/manifest index 8b8007bd0b..d4497c55a2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C The\stable_info\spragma\snow\sgives\sthe\sorder\sof\scolumns\sin\sthe\sprimary\skey.\s(CVS\s2694) -D 2005-09-15T21:24:52 +C Fix\sa\smemory\sleak:\sa\sfailure\sto\sdeallocate\sthe\sP3\sparameter\son\sa\scall\nto\ssqlite3VdbeChangeP3.\s(CVS\s2695) +D 2005-09-16T00:27:01 F Makefile.in 12784cdce5ffc8dfb707300c34e4f1eb3b8a14f1 F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -84,7 +84,7 @@ F src/vdbe.c 7b20b81b2643c0cc616c3fec6435f13c6e5fa6db F src/vdbe.h c8e105979fc7aaf5b8004e9621904e3bd096dfa2 F src/vdbeInt.h 3dd2a29c7b0a55404c35f93caae81fb42f4cb70a F src/vdbeapi.c 72213ce0c1ab8b215b2ae0ed342511bf769c1e60 -F src/vdbeaux.c 670264f8b8ddbc4277adf85ab945a59a3aaef871 +F src/vdbeaux.c df2bda6fdd8a7c9e99561b3975f36a2607912791 F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5 F src/vdbemem.c fea0744936008831daa17cdc75056c3ca1469690 F src/where.c 715e317eb37b89961ad7c5515a18f1e2eb1c7fd8 @@ -307,7 +307,7 @@ F www/tclsqlite.tcl ddcf912ea48695603c8ed7efb29f0812ef8d1b49 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 -P 81fdffdff6fd107c361b1ee69649455143bf3921 -R 5d6fa84265a140f10ff04dd28f842703 +P 9b60f48de7fbca96c6e26266a8fb9eed8bc378f2 +R 128fe9626d0d2bd0ae740c2610205a2e U drh -Z edb36e317a14972b7208ac1e96f014f6 +Z ed6250cc3e36da4b3eb7293f20c17966 diff --git a/manifest.uuid b/manifest.uuid index 4010b70e96..94176b4868 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9b60f48de7fbca96c6e26266a8fb9eed8bc378f2 \ No newline at end of file +714254cbc12564d44548707043fdcdffb17e4fde \ No newline at end of file diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 1096077050..742436d85e 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -68,9 +68,11 @@ static void resizeOpArray(Vdbe *p, int N){ p->aOp = sqliteRealloc(p->aOp, N*sizeof(Op)); }else if( p->nOpAllocnOpAlloc; + VdbeOp *pNew; p->nOpAlloc = N+100; - p->aOp = sqliteRealloc(p->aOp, p->nOpAlloc*sizeof(Op)); - if( p->aOp ){ + pNew = sqliteRealloc(p->aOp, p->nOpAlloc*sizeof(Op)); + if( pNew ){ + p->aOp = pNew; memset(&p->aOp[oldSize], 0, (p->nOpAlloc-oldSize)*sizeof(Op)); } } @@ -348,6 +350,27 @@ void sqlite3VdbeChangeP2(Vdbe *p, int addr, int val){ } } + +/* +** Delete a P3 value if necessary. +*/ +static void freeP3(int p3type, void *p3){ + if( p3 ){ + if( p3type==P3_DYNAMIC || p3type==P3_KEYINFO ){ + sqliteFree(p3); + } + if( p3type==P3_VDBEFUNC ){ + VdbeFunc *pVdbeFunc = (VdbeFunc *)p3; + sqlite3VdbeDeleteAuxData(pVdbeFunc, 0); + sqliteFree(pVdbeFunc); + } + if( p3type==P3_MEM ){ + sqlite3ValueFree((sqlite3_value*)p3); + } + } +} + + /* ** Change the value of the P3 operand for a specific instruction. ** This routine is useful when a large program is loaded from a @@ -377,12 +400,7 @@ void sqlite3VdbeChangeP3(Vdbe *p, int addr, const char *zP3, int n){ Op *pOp; assert( p->magic==VDBE_MAGIC_INIT ); if( p==0 || p->aOp==0 ){ - if( n==P3_DYNAMIC || n==P3_KEYINFO_HANDOFF ){ - sqliteFree((void*)zP3); - } - if( n==P3_MEM ){ - sqlite3ValueFree((sqlite3_value *)zP3); - } + freeP3(n, (void*)*(char**)&zP3); return; } if( addr<0 || addr>=p->nOp ){ @@ -390,10 +408,8 @@ void sqlite3VdbeChangeP3(Vdbe *p, int addr, const char *zP3, int n){ if( addr<0 ) return; } pOp = &p->aOp[addr]; - if( pOp->p3 && pOp->p3type==P3_DYNAMIC ){ - sqliteFree(pOp->p3); - pOp->p3 = 0; - } + freeP3(pOp->p3type, pOp->p3); + pOp->p3 = 0; if( zP3==0 ){ pOp->p3 = 0; pOp->p3type = P3_NOTUSED; @@ -1331,17 +1347,7 @@ void sqlite3VdbeDelete(Vdbe *p){ if( p->aOp ){ for(i=0; inOp; i++){ Op *pOp = &p->aOp[i]; - if( pOp->p3type==P3_DYNAMIC || pOp->p3type==P3_KEYINFO ){ - sqliteFree(pOp->p3); - } - if( pOp->p3type==P3_VDBEFUNC ){ - VdbeFunc *pVdbeFunc = (VdbeFunc *)pOp->p3; - sqlite3VdbeDeleteAuxData(pVdbeFunc, 0); - sqliteFree(pVdbeFunc); - } - if( pOp->p3type==P3_MEM ){ - sqlite3ValueFree((sqlite3_value*)pOp->p3); - } + freeP3(pOp->p3type, pOp->p3); } sqliteFree(p->aOp); }