aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordanielk1977 <danielk1977@noemail.net>2007-08-29 14:06:22 +0000
committerdanielk1977 <danielk1977@noemail.net>2007-08-29 14:06:22 +0000
commit26783a58e2206564f4db8a8bade9337a36a7b440 (patch)
tree03b0ed2f647f669f0d56aa1584b49a538c5a3334 /src
parentf53e9b5ad5ea62453fdc87e04e37d7ab309bc4f6 (diff)
downloadsqlite-26783a58e2206564f4db8a8bade9337a36a7b440.tar.gz
sqlite-26783a58e2206564f4db8a8bade9337a36a7b440.zip
Use the DbMalloc() and DbRealloc() functions more consistently. (CVS 4323)
FossilOrigin-Name: c790c234c369c6b7610e67dcaaa9eee347df729c
Diffstat (limited to 'src')
-rw-r--r--src/alter.c4
-rw-r--r--src/build.c13
-rw-r--r--src/expr.c5
-rw-r--r--src/func.c16
-rw-r--r--src/malloc.c6
-rw-r--r--src/table.c13
-rw-r--r--src/vdbeapi.c3
-rw-r--r--src/vdbemem.c4
-rw-r--r--src/vtab.c8
-rw-r--r--src/where.c5
10 files changed, 42 insertions, 35 deletions
diff --git a/src/alter.c b/src/alter.c
index bd87bb184..9d1ebd22c 100644
--- a/src/alter.c
+++ b/src/alter.c
@@ -12,7 +12,7 @@
** This file contains C code routines that used to generate VDBE code
** that implements the ALTER TABLE command.
**
-** $Id: alter.c,v 1.31 2007/08/29 04:00:58 drh Exp $
+** $Id: alter.c,v 1.32 2007/08/29 14:06:23 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -591,7 +591,7 @@ void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){
assert( pNew->nCol>0 );
nAlloc = (((pNew->nCol-1)/8)*8)+8;
assert( nAlloc>=pNew->nCol && nAlloc%8==0 && nAlloc-pNew->nCol<8 );
- pNew->aCol = (Column*)sqlite3MallocZero(sizeof(Column)*nAlloc);
+ pNew->aCol = (Column*)sqlite3DbMallocZero(db, sizeof(Column)*nAlloc);
pNew->zName = sqlite3DbStrDup(db, pTab->zName);
if( !pNew->aCol || !pNew->zName ){
db->mallocFailed = 1;
diff --git a/src/build.c b/src/build.c
index 047576134..430fe0070 100644
--- a/src/build.c
+++ b/src/build.c
@@ -22,7 +22,7 @@
** COMMIT
** ROLLBACK
**
-** $Id: build.c,v 1.441 2007/08/29 12:31:26 danielk1977 Exp $
+** $Id: build.c,v 1.442 2007/08/29 14:06:23 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -800,7 +800,7 @@ void sqlite3StartTable(
}
}
- pTable = sqlite3MallocZero( sizeof(Table) );
+ pTable = sqlite3DbMallocZero(db, sizeof(Table));
if( pTable==0 ){
db->mallocFailed = 1;
pParse->rc = SQLITE_NOMEM;
@@ -933,9 +933,8 @@ void sqlite3AddColumn(Parse *pParse, Token *pName){
}
if( (p->nCol & 0x7)==0 ){
Column *aNew;
- aNew = sqlite3_realloc( p->aCol, (p->nCol+8)*sizeof(p->aCol[0]));
+ aNew = sqlite3DbRealloc(pParse->db,p->aCol,(p->nCol+8)*sizeof(p->aCol[0]));
if( aNew==0 ){
- pParse->db->mallocFailed = 1;
sqlite3_free(z);
return;
}
@@ -2829,9 +2828,8 @@ void *sqlite3ArrayAllocate(
void *pNew;
int newSize;
newSize = (*pnAlloc)*2 + initSize;
- pNew = sqlite3_realloc(pArray, newSize*szEntry);
+ pNew = sqlite3DbRealloc(db, pArray, newSize*szEntry);
if( pNew==0 ){
- db->mallocFailed = 1;
*pIdx = -1;
return pArray;
}
@@ -2941,10 +2939,9 @@ SrcList *sqlite3SrcListAppend(
if( pList->nSrc>=pList->nAlloc ){
SrcList *pNew;
pList->nAlloc *= 2;
- pNew = sqlite3_realloc(pList,
+ pNew = sqlite3DbRealloc(db, pList,
sizeof(*pList) + (pList->nAlloc-1)*sizeof(pList->a[0]) );
if( pNew==0 ){
- db->mallocFailed = 1;
sqlite3SrcListDelete(pList);
return 0;
}
diff --git a/src/expr.c b/src/expr.c
index 778c65f3b..7465ab90b 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -12,7 +12,7 @@
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
-** $Id: expr.c,v 1.309 2007/08/29 12:31:26 danielk1977 Exp $
+** $Id: expr.c,v 1.310 2007/08/29 14:06:23 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -665,7 +665,7 @@ ExprList *sqlite3ExprListAppend(
if( pList->nAlloc<=pList->nExpr ){
struct ExprList_item *a;
int n = pList->nAlloc*2 + 4;
- a = sqlite3_realloc(pList->a, n*sizeof(pList->a[0]));
+ a = sqlite3DbRealloc(db, pList->a, n*sizeof(pList->a[0]));
if( a==0 ){
goto no_mem;
}
@@ -683,7 +683,6 @@ ExprList *sqlite3ExprListAppend(
no_mem:
/* Avoid leaking memory if malloc has failed. */
- db->mallocFailed = 1;
sqlite3ExprDelete(pExpr);
sqlite3ExprListDelete(pList);
return 0;
diff --git a/src/func.c b/src/func.c
index 989e29527..f530d3212 100644
--- a/src/func.c
+++ b/src/func.c
@@ -16,7 +16,7 @@
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
**
-** $Id: func.c,v 1.170 2007/08/29 12:31:26 danielk1977 Exp $
+** $Id: func.c,v 1.171 2007/08/29 14:06:23 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -234,6 +234,11 @@ static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
sqlite3_result_double(context, r);
}
+/*
+** Allocate nByte bytes of space using sqlite3_malloc(). If the
+** allocation fails, call sqlite3_result_error_nomem() to notify
+** the database handle that malloc() has failed.
+*/
static void *contextMalloc(sqlite3_context *context, int nByte){
char *z = sqlite3_malloc(nByte);
if( !z && nByte>0 ){
@@ -1074,10 +1079,11 @@ static void test_destructor(
assert( nArg==1 );
if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
len = sqlite3ValueBytes(argv[0], ENC(db));
- zVal = sqlite3MallocZero(len+3);
- zVal[len] = 0;
- zVal[len-1] = 0;
- assert( zVal );
+ zVal = contextMalloc(pCtx, len+3);
+ if( !zVal ){
+ return;
+ }
+ zVal[len+1] = 0;
zVal++;
memcpy(zVal, sqlite3ValueText(argv[0], ENC(db)), len);
if( ENC(db)==SQLITE_UTF8 ){
diff --git a/src/malloc.c b/src/malloc.c
index 5db775d8e..bc321ab9a 100644
--- a/src/malloc.c
+++ b/src/malloc.c
@@ -12,7 +12,7 @@
** Memory allocation functions used throughout sqlite.
**
**
-** $Id: malloc.c,v 1.12 2007/08/29 12:31:26 danielk1977 Exp $
+** $Id: malloc.c,v 1.13 2007/08/29 14:06:23 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
@@ -104,6 +104,10 @@ void *sqlite3DbMallocRaw(sqlite3 *db, unsigned n){
return p;
}
+/*
+** Resize the block of memory pointed to by p to n bytes. If the
+** resize fails, set the mallocFailed flag inthe connection object.
+*/
void *sqlite3DbRealloc(sqlite3 *db, void *p, int n){
void *pNew = 0;
if( db->mallocFailed==0 ){
diff --git a/src/table.c b/src/table.c
index 7a1be0f61..a79a6aca9 100644
--- a/src/table.c
+++ b/src/table.c
@@ -143,6 +143,11 @@ int sqlite3_get_table(
if( res.azResult==0 ) return SQLITE_NOMEM;
res.azResult[0] = 0;
rc = sqlite3_exec(db, zSql, sqlite3_get_table_cb, &res, pzErrMsg);
+#ifndef NDEBUG
+ sqlite3_mutex_enter(db->mutex);
+ assert((rc&db->errMask)==rc && (res.rc&db->errMask)==res.rc);
+ sqlite3_mutex_leave(db->mutex);
+#endif
if( res.azResult ){
assert( sizeof(res.azResult[0])>= sizeof(res.nData) );
res.azResult[0] = (char*)res.nData;
@@ -156,13 +161,15 @@ int sqlite3_get_table(
}
sqlite3_free(res.zErrMsg);
}
+ sqlite3_mutex_enter(db->mutex);
db->errCode = res.rc;
- return res.rc & db->errMask;
+ sqlite3_mutex_leave(db->mutex);
+ return res.rc;
}
sqlite3_free(res.zErrMsg);
if( rc!=SQLITE_OK ){
sqlite3_free_table(&res.azResult[1]);
- return rc & db->errMask;
+ return rc;
}
if( res.nAlloc>res.nData ){
char **azNew;
@@ -177,7 +184,7 @@ int sqlite3_get_table(
*pazResult = &res.azResult[1];
if( pnColumn ) *pnColumn = res.nColumn;
if( pnRow ) *pnRow = res.nRow;
- return rc & db->errMask;
+ return rc;
}
/*
diff --git a/src/vdbeapi.c b/src/vdbeapi.c
index 6716256c0..9445c7681 100644
--- a/src/vdbeapi.c
+++ b/src/vdbeapi.c
@@ -491,9 +491,8 @@ void sqlite3_set_auxdata(
if( !pVdbeFunc || pVdbeFunc->nAux<=iArg ){
int nAux = (pVdbeFunc ? pVdbeFunc->nAux : 0);
int nMalloc = sizeof(VdbeFunc) + sizeof(struct AuxData)*iArg;
- pVdbeFunc = sqlite3_realloc(pVdbeFunc, nMalloc);
+ pVdbeFunc = sqlite3DbRealloc(pCtx->s.db, pVdbeFunc, nMalloc);
if( !pVdbeFunc ){
- pCtx->s.db->mallocFailed = 1;
goto failed;
}
pCtx->pVdbeFunc = pVdbeFunc;
diff --git a/src/vdbemem.c b/src/vdbemem.c
index ef96b2fa2..58e294673 100644
--- a/src/vdbemem.c
+++ b/src/vdbemem.c
@@ -901,13 +901,11 @@ const void *sqlite3ValueText(sqlite3_value* pVal, u8 enc){
** Create a new sqlite3_value object.
*/
sqlite3_value *sqlite3ValueNew(sqlite3 *db){
- Mem *p = sqlite3MallocZero(sizeof(*p));
+ Mem *p = sqlite3DbMallocZero(db, sizeof(*p));
if( p ){
p->flags = MEM_Null;
p->type = SQLITE_NULL;
p->db = db;
- }else if( db ){
- db->mallocFailed = 1;
}
return p;
}
diff --git a/src/vtab.c b/src/vtab.c
index 7559bdefa..d1239fc4b 100644
--- a/src/vtab.c
+++ b/src/vtab.c
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to help implement virtual tables.
**
-** $Id: vtab.c,v 1.55 2007/08/29 12:31:29 danielk1977 Exp $
+** $Id: vtab.c,v 1.56 2007/08/29 14:06:23 danielk1977 Exp $
*/
#ifndef SQLITE_OMIT_VIRTUALTABLE
#include "sqliteInt.h"
@@ -136,7 +136,7 @@ static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){
int i = pTable->nModuleArg++;
int nBytes = sizeof(char *)*(1+pTable->nModuleArg);
char **azModuleArg;
- azModuleArg = sqlite3_realloc(pTable->azModuleArg, nBytes);
+ azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes);
if( azModuleArg==0 ){
int j;
for(j=0; j<i; j++){
@@ -145,7 +145,6 @@ static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){
sqlite3_free(zArg);
sqlite3_free(pTable->azModuleArg);
pTable->nModuleArg = 0;
- db->mallocFailed = 1;
}else{
azModuleArg[i] = zArg;
azModuleArg[i+1] = 0;
@@ -469,9 +468,8 @@ static int addToVTrans(sqlite3 *db, sqlite3_vtab *pVtab){
if( (db->nVTrans%ARRAY_INCR)==0 ){
sqlite3_vtab **aVTrans;
int nBytes = sizeof(sqlite3_vtab *) * (db->nVTrans + ARRAY_INCR);
- aVTrans = sqlite3_realloc((void *)db->aVTrans, nBytes);
+ aVTrans = sqlite3DbRealloc(db, (void *)db->aVTrans, nBytes);
if( !aVTrans ){
- db->mallocFailed = 1;
return SQLITE_NOMEM;
}
memset(&aVTrans[db->nVTrans], 0, sizeof(sqlite3_vtab *)*ARRAY_INCR);
diff --git a/src/where.c b/src/where.c
index 6f93f67ed..a9a3c7594 100644
--- a/src/where.c
+++ b/src/where.c
@@ -16,7 +16,7 @@
** so is applicable. Because this module is responsible for selecting
** indices, you might also think of this module as the "query optimizer".
**
-** $Id: where.c,v 1.258 2007/08/29 12:31:29 danielk1977 Exp $
+** $Id: where.c,v 1.259 2007/08/29 14:06:23 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -1260,11 +1260,10 @@ static double bestVirtualIndex(
/* Allocate the sqlite3_index_info structure
*/
- pIdxInfo = sqlite3MallocZero( sizeof(*pIdxInfo)
+ pIdxInfo = sqlite3DbMallocZero(pParse->db, sizeof(*pIdxInfo)
+ (sizeof(*pIdxCons) + sizeof(*pUsage))*nTerm
+ sizeof(*pIdxOrderBy)*nOrderBy );
if( pIdxInfo==0 ){
- pParse->db->mallocFailed = 1;
sqlite3ErrorMsg(pParse, "out of memory");
return 0.0;
}