Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Fix handling of a failed malloc() in various places (CVS 1604) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
7d8edce4c12d075acbc6bac6758aabb2 |
User & Date: | danielk1977 2004-06-16 10:39:24.000 |
Context
2004-06-16
| ||
10:39 | Fix handling of a failed malloc() in various places (CVS 1605) (check-in: b739ef2a1b user: danielk1977 tags: trunk) | |
10:39 | Fix handling of a failed malloc() in various places (CVS 1604) (check-in: 7d8edce4c1 user: danielk1977 tags: trunk) | |
07:45 | Fix two more memory leaks. (CVS 1603) (check-in: 98b48704a1 user: danielk1977 tags: trunk) | |
Changes
Changes to src/func.c.
︙ | ︙ | |||
12 13 14 15 16 17 18 | ** This file contains the C functions that implement various SQL ** functions of SQLite. ** ** There is only one exported symbol in this file - the function ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. ** | | | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ** This file contains the C functions that implement various SQL ** functions of SQLite. ** ** There is only one exported symbol in this file - the function ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. ** ** $Id: func.c,v 1.70 2004/06/16 10:39:24 danielk1977 Exp $ */ #include <ctype.h> #include <math.h> #include <stdlib.h> #include <assert.h> #include "sqliteInt.h" #include "vdbeInt.h" |
︙ | ︙ | |||
900 901 902 903 904 905 906 | */ static void minmaxStep(sqlite3_context *context, int argc, sqlite3_value **argv){ int max = 0; int cmp = 0; Mem *pArg = (Mem *)argv[0]; Mem *pBest = (Mem *)sqlite3_aggregate_context(context, sizeof(*pBest)); | | < | 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 | */ static void minmaxStep(sqlite3_context *context, int argc, sqlite3_value **argv){ int max = 0; int cmp = 0; Mem *pArg = (Mem *)argv[0]; Mem *pBest = (Mem *)sqlite3_aggregate_context(context, sizeof(*pBest)); if( !pBest || SQLITE_NULL==sqlite3_value_type(argv[0]) ) return; if( pBest->flags ){ CollSeq *pColl = sqlite3GetFuncCollSeq(context); /* This step function is used for both the min() and max() aggregates, ** the only difference between the two being that the sense of the ** comparison is inverted. For the max() aggregate, the ** sqlite3_user_data() function returns (void *)-1. For min() it ** returns (void *)db, where db is the sqlite3* database pointer. |
︙ | ︙ |
Changes to src/main.c.
︙ | ︙ | |||
10 11 12 13 14 15 16 | ** ************************************************************************* ** Main file for the SQLite library. The routines in this file ** implement the programmer interface to the library. Routines in ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** | | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ** ************************************************************************* ** Main file for the SQLite library. The routines in this file ** implement the programmer interface to the library. Routines in ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** ** $Id: main.c,v 1.223 2004/06/16 10:39:32 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> /* ** A pointer to this structure is used to communicate information |
︙ | ︙ | |||
467 468 469 470 471 472 473 474 475 476 477 478 479 480 | /* ** Close an existing SQLite database */ void sqlite3_close(sqlite *db){ HashElem *i; int j; db->want_to_close = 1; /* FIX ME: db->magic may be set to SQLITE_MAGIC_CLOSED if the database ** cannot be opened for some reason. So this routine needs to run in ** that case. But maybe there should be an extra magic value for the ** "failed to open" state. */ | > > > > | 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 | /* ** Close an existing SQLite database */ void sqlite3_close(sqlite *db){ HashElem *i; int j; if( !db ){ return; } db->want_to_close = 1; /* FIX ME: db->magic may be set to SQLITE_MAGIC_CLOSED if the database ** cannot be opened for some reason. So this routine needs to run in ** that case. But maybe there should be an extra magic value for the ** "failed to open" state. */ |
︙ | ︙ | |||
888 889 890 891 892 893 894 895 896 897 898 899 900 901 | db->zErrMsg16 = sqlite3utf8to16le(zErr8, -1); } } return db->zErrMsg16; } int sqlite3_errcode(sqlite3 *db){ return db->errCode; } /* ** Check schema cookies in all databases except TEMP. If any cookie is out ** of date, return 0. If all schema cookies are current, return 1. */ | > | 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 | db->zErrMsg16 = sqlite3utf8to16le(zErr8, -1); } } return db->zErrMsg16; } int sqlite3_errcode(sqlite3 *db){ if( !db ) return SQLITE_NOMEM; return db->errCode; } /* ** Check schema cookies in all databases except TEMP. If any cookie is out ** of date, return 0. If all schema cookies are current, return 1. */ |
︙ | ︙ | |||
933 934 935 936 937 938 939 940 941 942 943 944 945 946 | sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */ const char** pzTail /* OUT: End of parsed string */ ){ Parse sParse; char *zErrMsg = 0; int rc = SQLITE_OK; if( sqlite3SafetyOn(db) ){ rc = SQLITE_MISUSE; goto prepare_out; } if( db->pVdbe==0 ){ db->nChange = 0; } memset(&sParse, 0, sizeof(sParse)); | > > | 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 | sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */ const char** pzTail /* OUT: End of parsed string */ ){ Parse sParse; char *zErrMsg = 0; int rc = SQLITE_OK; assert( ppStmt ); *ppStmt = 0; if( sqlite3SafetyOn(db) ){ rc = SQLITE_MISUSE; goto prepare_out; } if( db->pVdbe==0 ){ db->nChange = 0; } memset(&sParse, 0, sizeof(sParse)); |
︙ | ︙ | |||
991 992 993 994 995 996 997 | if( sParse.rc==SQLITE_DONE ) sParse.rc = SQLITE_OK; if( sParse.checkSchema && !schemaIsValid(db) ){ sParse.rc = SQLITE_SCHEMA; } if( sParse.rc==SQLITE_SCHEMA ){ sqlite3ResetInternalSchema(db, 0); } | < < > > > > > > | 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 | if( sParse.rc==SQLITE_DONE ) sParse.rc = SQLITE_OK; if( sParse.checkSchema && !schemaIsValid(db) ){ sParse.rc = SQLITE_SCHEMA; } if( sParse.rc==SQLITE_SCHEMA ){ sqlite3ResetInternalSchema(db, 0); } if( pzTail ) *pzTail = sParse.zTail; rc = sParse.rc; if( rc==SQLITE_OK && sParse.pVdbe && sParse.explain ){ sqlite3VdbeSetNumCols(sParse.pVdbe, 5); sqlite3VdbeSetColName(sParse.pVdbe, 0, "addr", P3_STATIC); sqlite3VdbeSetColName(sParse.pVdbe, 1, "opcode", P3_STATIC); sqlite3VdbeSetColName(sParse.pVdbe, 2, "p1", P3_STATIC); sqlite3VdbeSetColName(sParse.pVdbe, 3, "p2", P3_STATIC); sqlite3VdbeSetColName(sParse.pVdbe, 4, "p3", P3_STATIC); } prepare_out: if( sqlite3SafetyOff(db) ){ rc = SQLITE_MISUSE; } if( rc==SQLITE_OK ){ *ppStmt = (sqlite3_stmt*)sParse.pVdbe; }else if( sParse.pVdbe ){ sqlite3_finalize(sParse.pVdbe); } if( zErrMsg ){ sqlite3Error(db, rc, "%s", zErrMsg); sqliteFree(zErrMsg); }else{ sqlite3Error(db, rc, 0); } return rc; |
︙ | ︙ |