:-) (CVS 29)
FossilOrigin-Name: 09054df318240f2f2b365f7b24655473c1ab6655
diff --git a/src/dbbe.c b/src/dbbe.c
index c6040ba..6d8ed42 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 <gdbm.h>
@@ -559,6 +559,7 @@
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 4bbc75c..4deac6d 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 @@
if( pzErrMsg ) *pzErrMsg = 0;
if( db==0 ){
sqliteSetString(pzErrMsg, "out of memory", 0);
+ sqliteStrRealloc(pzErrMsg);
return 0;
}
@@ -215,5 +216,6 @@
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 0dd8ef8..08deeb2 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 <string.h>
#include <assert.h>
-/* #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 b5bf19c..23789fd 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 <stdarg.h>
@@ -51,7 +51,9 @@
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 @@
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 @@
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 @@
}
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