]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix the memory leak introduced by check-in (725). (CVS 726)
authordrh <drh@noemail.net>
Sun, 25 Aug 2002 18:29:11 +0000 (18:29 +0000)
committerdrh <drh@noemail.net>
Sun, 25 Aug 2002 18:29:11 +0000 (18:29 +0000)
FossilOrigin-Name: b957dafc26383af514795df18bc7b8f367c9bd21

manifest
manifest.uuid
src/select.c
src/util.c
src/vdbe.c
test/view.test
tool/memleak.awk

index b768d722b3babe009de65808448fb3338eada7ed..16c4d104f41751ceba12199cee74ff1969751d9a 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Change\sthe\sway\stoken\smemory\sis\sallocated\sin\san\seffort\sto\sfix\sticket\s#136.\nThere\sis\snow\sa\smemory\sleak\swhen\susing\sviews\sof\sviews.\s(CVS\s725)
-D 2002-08-24T18:24:52
+C Fix\sthe\smemory\sleak\sintroduced\sby\scheck-in\s(725).\s(CVS\s726)
+D 2002-08-25T18:29:12
 F Makefile.in bcb81f40d9a17bd94f59e67157b1e1c54c046c2b
 F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -37,7 +37,7 @@ F src/pager.h 6991c9c2dc5e4c7f2df4d4ba47d1c6458f763a32
 F src/parse.y 1b180e14b6346e323bd4279469748716f412cc1c
 F src/printf.c 5c50fc1da75c8f5bf432b1ad17d91d6653acd167
 F src/random.c 19e8e00fe0df32a742f115773f57651be327cabe
-F src/select.c 7aa3c3784452ca8f154ae9b3b250ccedc1633354
+F src/select.c bef25919ad813685d60d03a393728bf5766ec0cb
 F src/shell.c 9e9a6eb6bca07f01e6472a603f908a0127ea50ff
 F src/shell.tcl 27ecbd63dd88396ad16d81ab44f73e6c0ea9d20e
 F src/sqlite.h.in d3999a9c6374675779058d6cfe5431131618e92b
@@ -51,8 +51,8 @@ F src/threadtest.c 72bce0a284647314847bbea44616ceb056bfb77f
 F src/tokenize.c 8bd6251e5237c9a16d0bbfb9894925eb129985fa
 F src/trigger.c cc8c6769c2ca37166490ed2b305986268faa3bf8
 F src/update.c f07e6ed2c517c92871e54d3f5886d1cf56121b11
-F src/util.c bdbf0aedcec21ede2248126bbbe734bcc070b7c8
-F src/vdbe.c 5b3bb8ac3bb8dd777abd9fae64a293bfdcc13c54
+F src/util.c 60bc91db77cf488618ec4720cb06eedb7f959268
+F src/vdbe.c 92bcd4661641fba76680c762971bdca7995594d6
 F src/vdbe.h a9292f2b5fcecef924fa255fb74609e9cbc776c2
 F src/where.c ce42cce65d7bf42341627f3fb0a17f69fea6a4f4
 F test/all.test efd958d048c70a3247997c482f0b33561f7759f0
@@ -109,12 +109,12 @@ F test/unique.test 572aa791327c1e8d797932263e9d67f176cfdb44
 F test/update.test 7ffb062d580a972e7870d0f51d5af3ab9bfeae08
 F test/vacuum.test 059871b312eb910bbe49dafde1d01490cc2c6bbe
 F test/version.test c7057526e14c7e3da5718b88e7f566f4182fd5c5
-F test/view.test e4d60d68ea3965fe0cc8fa83ba9aa42e23199801
+F test/view.test ed18cebaa19fa949cad4bc7e7f2d8d71001153cf
 F test/where.test c7aba40ad9178acf9c898e53aac9e447e2d2f2f7
 F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b
 F tool/lemon.c 022adc2830c2705828f744d2c59798bd462eb465
 F tool/lempar.c 73a991cc3017fb34804250fa901488b5147b3717
-F tool/memleak.awk 296dfbce7a9ca499b95ce04e30334e64a50052e0
+F tool/memleak.awk 16ef9493dcd36146f806e75148f4bb0201a123ec
 F tool/opNames.awk 5ba1f48aa854ee3b7c3d2b54233665bc3e649ea2
 F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c
 F tool/renumberOps.awk 6d067177ad5f8d711b79577b462da9b3634bd0a9
@@ -147,7 +147,7 @@ F www/speed.tcl a20a792738475b68756ea7a19321600f23d1d803
 F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098
 F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
-P 97fc4a71a12b52cda67b5192c3bd7bd10ac0c7a6
-R e9cbaf493a319211c9d9a2010395d53a
+P 22d8726e61eec0e53893f492cb2163824b87a23e
+R 4234452349011dbb44aad5f2e4ed57e1
 U drh
-Z df71dce9abf1e8c9e6b3a2493526cd33
+Z 4b5d6fc436ecc6188dd50e32ce24f78e
index 7c2851e09d20620f56f612de2ff5e38376e82b87..b8c64762c1210e5e75cc5fd0bb9c8f8fe5bbf20e 100644 (file)
@@ -1 +1 @@
-22d8726e61eec0e53893f492cb2163824b87a23e
\ No newline at end of file
+b957dafc26383af514795df18bc7b8f367c9bd21
\ No newline at end of file
index 2171ead1b3dee308c2a8c493d5a9e47b4bea43ef..73d766227e9ada0f762bfb951ea65787fb8a1aa1 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains C code routines that are called by the parser
 ** to handle SELECT statements in SQLite.
 **
-** $Id: select.c,v 1.108 2002/08/24 18:24:54 drh Exp $
+** $Id: select.c,v 1.109 2002/08/25 18:29:12 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -808,6 +808,7 @@ static int fillInColumnList(Parse *pParse, Select *p){
         if( sqliteViewGetColumnNames(pParse, pTab) ){
           return 1;
         }
+        sqliteSelectDelete(pTabList->a[i].pSelect);
         pTabList->a[i].pSelect = sqliteSelectDup(pTab->pSelect);
       }
     }
@@ -1309,8 +1310,11 @@ static void substExpr(Expr *pExpr, int iTable, ExprList *pEList, int iSub){
     pNew = pEList->a[pExpr->iColumn].pExpr;
     assert( pNew!=0 );
     pExpr->op = pNew->op;
+    assert( pExpr->pLeft==0 );
     pExpr->pLeft = sqliteExprDup(pNew->pLeft);
+    assert( pExpr->pRight==0 );
     pExpr->pRight = sqliteExprDup(pNew->pRight);
+    assert( pExpr->pList==0 );
     pExpr->pList = sqliteExprListDup(pNew->pList);
     pExpr->iTable = pNew->iTable;
     pExpr->iColumn = pNew->iColumn;
@@ -1495,6 +1499,7 @@ int flattenSubquery(Select *p, int iFrom, int isAgg, int subqueryIsAgg){
   }
   pSrc->a[iFrom].pTab = pSubSrc->a[0].pTab;
   pSubSrc->a[0].pTab = 0;
+  assert( pSrc->a[iFrom].pSelect==pSub );
   pSrc->a[iFrom].pSelect = pSubSrc->a[0].pSelect;
   pSubSrc->a[0].pSelect = 0;
   sqliteSelectDelete(pSub);
index 11f9f752e98ec0d54481f17c2c180ea16617f410..200a14c376a0ff77f17220adbc0a70648be3523a 100644 (file)
@@ -14,7 +14,7 @@
 ** This file contains functions for allocating memory, comparing
 ** strings, and stuff like that.
 **
-** $Id: util.c,v 1.48 2002/08/13 23:02:57 drh Exp $
+** $Id: util.c,v 1.49 2002/08/25 18:29:12 drh Exp $
 */
 #include "sqliteInt.h"
 #include <stdarg.h>
@@ -39,6 +39,9 @@ int sqlite_malloc_failed = 0;
 int sqlite_nMalloc;         /* Number of sqliteMalloc() calls */
 int sqlite_nFree;           /* Number of sqliteFree() calls */
 int sqlite_iMallocFail;     /* Fail sqliteMalloc() after this many calls */
+#if MEMORY_DEBUG>1
+static int memcnt = 0;
+#endif
 
 
 /*
@@ -75,7 +78,8 @@ void *sqliteMalloc_(int n, char *zFile, int line){
   p = &pi[2];
   memset(p, 0, n);
 #if MEMORY_DEBUG>1
-  fprintf(stderr,"malloc %d bytes at 0x%x from %s:%d\n", n, (int)p, zFile,line);
+  fprintf(stderr,"%06d malloc %d bytes at 0x%x from %s:%d\n",
+      ++memcnt, n, (int)p, zFile,line);
 #endif
   return p;
 }
@@ -101,7 +105,8 @@ void sqliteFree_(void *p, char *zFile, int line){
     }
     memset(pi, 0xff, (k+3)*sizeof(int));
 #if MEMORY_DEBUG>1
-    fprintf(stderr,"free %d bytes at 0x%x from %s:%d\n", n, (int)p, zFile,line);
+    fprintf(stderr,"%06d free %d bytes at 0x%x from %s:%d\n",
+         ++memcnt, n, (int)p, zFile,line);
 #endif
     free(pi);
   }
@@ -151,8 +156,8 @@ void *sqliteRealloc_(void *oldP, int n, char *zFile, int line){
   memset(oldPi, 0, (oldK+3)*sizeof(int));
   free(oldPi);
 #if MEMORY_DEBUG>1
-  fprintf(stderr,"realloc %d to %d bytes at 0x%x to 0x%x at %s:%d\n", oldN, n,
-    (int)oldP, (int)p, zFile, line);
+  fprintf(stderr,"%06d realloc %d to %d bytes at 0x%x to 0x%x at %s:%d\n",
+    ++memcnt, oldN, n, (int)oldP, (int)p, zFile, line);
 #endif
   return p;
 }
index 6923951f94ba8b6f231d4c2e21c35e24528a6be4..4a7e2de9138ee05b93e88ffd45810c181707f52c 100644 (file)
@@ -30,7 +30,7 @@
 ** But other routines are also provided to help in building up
 ** a program instruction by instruction.
 **
-** $Id: vdbe.c,v 1.169 2002/08/15 01:26:10 drh Exp $
+** $Id: vdbe.c,v 1.170 2002/08/25 18:29:13 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -252,6 +252,16 @@ struct Vdbe {
   Keylist **keylistStack; /* The stack used by opcodes ListPush & ListPop */
 };
 
+/*
+** When debugging the code generator in a symbolic debugger, on can
+** set the sqlite_vdbe_addop_trace to 1 and all opcodes will be printed
+** as they are added to the instruction stream.
+*/
+#ifndef NDEBUG
+int sqlite_vdbe_addop_trace = 0;
+static void vdbePrintOp(FILE*, int, Op*);
+#endif
+
 /*
 ** Create a new virtual database engine.
 */
@@ -312,6 +322,9 @@ int sqliteVdbeAddOp(Vdbe *p, int op, int p1, int p2){
   p->aOp[i].p2 = p2;
   p->aOp[i].p3 = 0;
   p->aOp[i].p3type = P3_NOTUSED;
+#ifndef NDEBUG
+  if( sqlite_vdbe_addop_trace ) vdbePrintOp(0, i, &p->aOp[i]);
+#endif
   return i;
 }
 
@@ -397,6 +410,9 @@ int sqliteVdbeAddOpList(Vdbe *p, int nOp, VdbeOp const *aOp){
       p->aOp[i+addr] = aOp[i];
       if( p2<0 ) p->aOp[i+addr].p2 = addr + ADDR(p2);
       p->aOp[i+addr].p3type = aOp[i].p3 ? P3_STATIC : P3_NOTUSED;
+#ifndef NDEBUG
+      if( sqlite_vdbe_addop_trace ) vdbePrintOp(0, i+addr, &p->aOp[i+addr]);
+#endif
     }
     p->nOp += nOp;
   }
@@ -1266,6 +1282,26 @@ static char *vdbe_fgets(char *zBuf, int nBuf, FILE *in){
   return i>0 ? zBuf : 0;
 }
 
+#ifndef NDEBUG
+/*
+** Print a single opcode.  This routine is used for debugging only.
+*/
+static void vdbePrintOp(FILE *pOut, int pc, Op *pOp){
+  char *zP3;
+  char zPtr[40];
+  if( pOp->p3type==P3_POINTER ){
+    sprintf(zPtr, "ptr(%#x)", (int)pOp->p3);
+    zP3 = zPtr;
+  }else{
+    zP3 = pOp->p3;
+  }
+  if( pOut==0 ) pOut = stdout;
+  fprintf(pOut,"%4d %-12s %4d %4d %s\n",
+      pc, zOpName[pOp->opcode], pOp->p1, pOp->p2, zP3 ? zP3 : "");
+  fflush(pOut);
+}
+#endif
+
 /*
 ** Execute the program in the VDBE.
 **
@@ -1358,17 +1394,7 @@ int sqliteVdbeExec(
     */
 #ifndef NDEBUG
     if( p->trace ){
-      char *zP3;
-      char zPtr[40];
-      if( pOp->p3type==P3_POINTER ){
-        sprintf(zPtr, "ptr(%#x)", (int)pOp->p3);
-        zP3 = zPtr;
-      }else{
-        zP3 = pOp->p3;
-      }
-      fprintf(p->trace,"%4d %-12s %4d %4d %s\n",
-        pc, zOpName[pOp->opcode], pOp->p1, pOp->p2, zP3 ? zP3 : "");
-      fflush(p->trace);
+      vdbePrintOp(p->trace, pc, pOp);
     }
 #endif
 
index c60f15bf97d0770b8fc6c544e70e2040294c664e..95f90cccede56698fbd44841d8ef58c181219488 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing VIEW statements.
 #
-# $Id: view.test,v 1.9 2002/08/24 18:24:57 drh Exp $
+# $Id: view.test,v 1.10 2002/08/25 18:29:16 drh Exp $
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
 
@@ -271,7 +271,6 @@ do_test view-8.1 {
     SELECT * FROM v6 ORDER BY xyz;
   }
 } {7 2 13 5 19 8 27 12}
-if 0 {
 do_test view-8.2 {
   db close
   sqlite db test.db
@@ -285,6 +284,7 @@ do_test view-8.3 {
     SELECT * FROM v7 ORDER BY a;
   }
 } {9 18 27 39}
+if 0 {
 do_test view-8.4 {
   execsql { PRAGMA vdbe_trace=on;
     CREATE VIEW v8 AS SELECT max(cnt) FROM
index b19787e834b680984e3dc91808f78362c21a5dcb..bf12cb406b9565a2b3e98299d84d8f1d2d276dbc 100644 (file)
@@ -2,19 +2,19 @@
 # This script looks for memory leaks by analyzing the output of "sqlite" 
 # when compiled with the MEMORY_DEBUG=2 option.
 #
-/^malloc / {
-  mem[$5] = $0
+/[0-9]+ malloc / {
+  mem[$6] = $0
 }
-/^realloc / {
-  mem[$7] = "";
-  mem[$9] = $0
+/[0-9]+ realloc / {
+  mem[$8] = "";
+  mem[$10] = $0
 }
-/^free / {
-  mem[$5] = "";
-  str[$5] = ""
+/[0-9]+ free / {
+  mem[$6] = "";
+  str[$6] = ""
 }
 /^string at / {
-  addr = $3
+  addr = $4
   sub("string at " addr " is ","")
   str[addr] = $0
 }