From c3c2fc9a4906b19070a8a0d88e16d5ab3a91fdb1 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 31 May 2000 22:58:39 +0000 Subject: [PATCH] :-) (CVS 29) FossilOrigin-Name: 09054df318240f2f2b365f7b24655473c1ab6655 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/dbbe.c | 3 ++- src/main.c | 4 +++- src/sqliteInt.h | 7 +++++-- src/util.c | 38 +++++++++++++++++++++++++++++--------- 6 files changed, 49 insertions(+), 23 deletions(-) diff --git a/manifest b/manifest index 9454a21529..044b5d2058 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C :-)\s(CVS\s28) -D 2000-05-31T21:06:30 +C :-)\s(CVS\s29) +D 2000-05-31T22:58:39 F COPYRIGHT 74a8a6531a42e124df07ab5599aad63870fa0bd4 F Makefile.in 7ac2fef265940d93a544cb454efa836451559a71 F README 6b5960603c7f8bf42fc022b4b6436f242f238dbb @@ -7,21 +7,21 @@ F configure 00a5b5c82147a576fa6e82d7c1b0d55c321d6d2c x F configure.in 6ccfd5fc80517f7cfe605a7fc7e0f62d962a233c F doc/lemon.html e233a3e97a779c7a87e1bc4528c664a58e49dd47 F src/build.c 03f83e95d46e328a2ac08aace102b142ea38e6d7 -F src/dbbe.c 3635022e50ab1632825be6a14f74eb29014e895f +F src/dbbe.c da2bb60d72f848ed38b96ee01d163aa98592d52a F src/dbbe.h 0147c9f8539d421d6c5558d3e854b78387372fae F src/delete.c 16ef3418b19be9ab39db836c693970ca7bbff605 F src/expr.c 91970700e3e39b2b725b028c166f588a5bb0c038 F src/insert.c bd34716d0bba5561f6b55101adbf16fa75f872e8 -F src/main.c 25cce7bce0eb3ba10bada7c05f4b38dc6dbbc86f +F src/main.c a14b1e8837836e59eb4855bf22879c7139892276 F src/parse.y 16322c46ec117082ef745715f7a4761f2491a0b2 F src/select.c 25cada7cb2b0b4973b3e17c81ba1b1c887829f71 F src/shell.c c5752d32cdeaa7d548d4f91177b697b023a00381 F src/sqlite.h 2397c17a8f4ca90c09acab0100dc7e2f8f441b69 -F src/sqliteInt.h 04f38613a8ecedfdb15b21175acf0fe2ce55e299 +F src/sqliteInt.h a3c662ff65826f3b51d4aa946b4201e864c4587c F src/tclsqlite.c 9efd29f79ded6a900aa3d142169c8bfe03b7affd F src/tokenize.c 15c229fee77325334c6814652e429b0930eba6c1 F src/update.c 9194f548dafc9884d79489874e22974ed67cd6a2 -F src/util.c 6b4327d7fbf684f8635155d4acb847ae991b3ebc +F src/util.c da47fe65efa6ff4c5e663cc7c832964bd599c0d2 F src/vdbe.c a60a9316f2ffbc020d5a9a73535b84e7f513e45d F src/vdbe.h ab574c91c6328c5795f68b84074fbcf860eae70e F src/where.c bed9a8360cbfbf712bdc397c8e22216a5e5f9800 @@ -45,7 +45,7 @@ F www/c_interface.tcl f875864edf7974157d1c257ca08de854660882a5 F www/changes.tcl 37f4906f0b03f2160d2b2e4ed3cedb0b91d253cb F www/index.tcl a94e31dc690f07b0dfdb82c5ab6315e4840a336d F www/sqlite.tcl 7deb564df188ad4523adecfe2365de6d09f6dfd9 -P 1f0c4ffd98591e506201b6b0e6e60b9216ceb596 -R 0f2e2968ed9c0d0c28efc76f372593a3 +P 57c5add197c12c919e2556b5ac421803398f2c1b +R f5b36e27fa2bef5aa09105fe5f4f6aab U drh -Z 0827c57252d4cd13107c7c9e774afaee +Z 8e27228f5e9143eb165e86ff6773e689 diff --git a/manifest.uuid b/manifest.uuid index 5c9a0c0890..8c1fc379dc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -57c5add197c12c919e2556b5ac421803398f2c1b \ No newline at end of file +09054df318240f2f2b365f7b24655473c1ab6655 \ No newline at end of file diff --git a/src/dbbe.c b/src/dbbe.c index c6040bae0c..6d8ed4222d 100644 --- a/src/dbbe.c +++ b/src/dbbe.c @@ -30,7 +30,7 @@ ** relatively simple to convert to a different database such ** as NDBM, SDBM, or BerkeleyDB. ** -** $Id: dbbe.c,v 1.5 2000/05/31 21:06:30 drh Exp $ +** $Id: dbbe.c,v 1.6 2000/05/31 22:58:39 drh Exp $ */ #include "sqliteInt.h" #include @@ -559,6 +559,7 @@ FILE *sqliteDbbeOpenTempFile(Dbbe *pBe){ do{ randomName(&pBe->rc4, zBuf, "/_temp_file_"); sqliteFree(zFile); + zFile = 0; sqliteSetString(&zFile, pBe->zDir, zBuf, 0); }while( access(zFile,0)==0 && limit-- >= 0 ); pBe->apTemp[i] = fopen(zFile, "w+"); diff --git a/src/main.c b/src/main.c index 4bbc75cedd..4deac6de0d 100644 --- a/src/main.c +++ b/src/main.c @@ -26,7 +26,7 @@ ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** -** $Id: main.c,v 1.1 2000/05/29 14:26:01 drh Exp $ +** $Id: main.c,v 1.2 2000/05/31 22:58:39 drh Exp $ */ #include "sqliteInt.h" @@ -121,6 +121,7 @@ sqlite *sqlite_open(const char *zFilename, int mode, char **pzErrMsg){ if( pzErrMsg ) *pzErrMsg = 0; if( db==0 ){ sqliteSetString(pzErrMsg, "out of memory", 0); + sqliteStrRealloc(pzErrMsg); return 0; } @@ -215,5 +216,6 @@ int sqlite_exec( sParse.xCallback = xCallback; sParse.pArg = pArg; nErr = sqliteRunParser(&sParse, zSql, pzErrMsg); + sqliteStrRealloc(pzErrMsg); return nErr; } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 0dd8ef8251..08deeb275c 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -23,7 +23,7 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.6 2000/05/31 20:00:52 drh Exp $ +** @(#) $Id: sqliteInt.h,v 1.7 2000/05/31 22:58:39 drh Exp $ */ #include "sqlite.h" #include "dbbe.h" @@ -35,11 +35,14 @@ #include #include -/* #define MEMORY_DEBUG 1 */ +/* #define MEMORY_DEBUG 2 */ #ifdef MEMORY_DEBUG # define sqliteMalloc(X) sqliteMalloc_(X,__FILE__,__LINE__) # define sqliteFree(X) sqliteFree_(X,__FILE__,__LINE__) # define sqliteRealloc(X,Y) sqliteRealloc_(X,Y,__FILE__,__LINE__) + void sqliteStrRealloc(char**); +#else +# define sqliteStrRealloc(X) #endif /* diff --git a/src/util.c b/src/util.c index b5bf19ca65..23789fdc40 100644 --- a/src/util.c +++ b/src/util.c @@ -26,7 +26,7 @@ ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** -** $Id: util.c,v 1.7 2000/05/31 02:27:49 drh Exp $ +** $Id: util.c,v 1.8 2000/05/31 22:58:39 drh Exp $ */ #include "sqliteInt.h" #include @@ -51,7 +51,9 @@ void *sqliteMalloc_(int n, char *zFile, int line){ pi[k+2] = 0xdead3344; p = &pi[2]; memset(p, 0, n); - printf("malloc %d bytes at 0x%x from %s:%d\n", n, (int)p, zFile, line); +#if MEMORY_DEBUG>1 + fprintf(stderr,"malloc %d bytes at 0x%x from %s:%d\n", n, (int)p, zFile,line); +#endif return p; } @@ -64,17 +66,19 @@ void sqliteFree_(void *p, char *zFile, int line){ pi = p; pi -= 2; if( pi[0]!=0xdead1122 ){ - printf("Low-end memory corruption at 0x%x\n", (int)p); + fprintf(stderr,"Low-end memory corruption at 0x%x\n", (int)p); return; } n = pi[1]; k = (n+sizeof(int)-1)/sizeof(int); if( pi[k+2]!=0xdead3344 ){ - printf("High-end memory corruption at 0x%x\n", (int)p); + fprintf(stderr,"High-end memory corruption at 0x%x\n", (int)p); return; } - memset(pi, 0, (k+3)*sizeof(int)); - printf("free %d bytes at 0x%x from %s:%d\n", n, (int)p, zFile, 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); +#endif free(pi); } } @@ -97,13 +101,13 @@ void *sqliteRealloc_(void *oldP, int n, char *zFile, int line){ oldPi = oldP; oldPi -= 2; if( oldPi[0]!=0xdead1122 ){ - printf("Low-end memory corruption in realloc at 0x%x\n", (int)p); + fprintf(stderr,"Low-end memory corruption in realloc at 0x%x\n", (int)p); return; } oldN = oldPi[1]; oldK = (oldN+sizeof(int)-1)/sizeof(int); if( oldPi[oldK+2]!=0xdead3344 ){ - printf("High-end memory corruption in realloc at 0x%x\n", (int)p); + fprintf(stderr,"High-end memory corruption in realloc at 0x%x\n", (int)p); return; } k = (n + sizeof(int) - 1)/sizeof(int); @@ -118,10 +122,26 @@ void *sqliteRealloc_(void *oldP, int n, char *zFile, int line){ } memset(oldPi, 0, (oldK+3)*sizeof(int)); free(oldPi); - printf("realloc %d->%d bytes at 0x%x->0x%x at %s:%d\n", oldN, n, +#if MEMORY_DEBUG>1 + fprintf(stderr,"realloc %d->%d bytes at 0x%x->0x%x at %s:%d\n", oldN, n, (int)oldP, (int)p, zFile, line); +#endif return p; } + +/* +** Make a duplicate of a string into memory obtained from malloc() +** Free the original string using sqliteFree(). +*/ +void sqliteStrRealloc(char **pz){ + char *zNew; + if( pz==0 || *pz==0 ) return; + zNew = malloc( strlen(*pz) + 1 ); + if( zNew ) strcpy(zNew, *pz); + sqliteFree(*pz); + *pz = zNew; +} + #else /* !defined(MEMORY_DEBUG) */ /* ** Allocate new memory and set it to zero. Return NULL if