Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Changes In Branch malloc-enhancement Excluding Merge-Ins
This is equivalent to a diff from a6bb2108 to 548bf3f7
2010-07-26
| ||
16:24 | Add support for SQLITE_DBSTATUS_SCHEMA_USED and SQLITE_DBSTATUS_STMT_USED to the trunk. (check-in: 008368b2 user: drh tags: trunk) | |
2010-07-25
| ||
02:39 | Fixes to prior checkins so that they compile and run even if SQLITE_MEMDEBUG is not defined. (Closed-Leaf check-in: 548bf3f7 user: drh tags: malloc-enhancement) | |
02:12 | Further examples of using automatic deallocation to replace "delete" methods. (check-in: da2f62c5 user: drh tags: malloc-enhancement) | |
2010-07-24
| ||
16:34 | Make sure all memory from sqlite3DbMalloc() is freed by sqlite3DbFree() and all memory from sqlite3_malloc() is freed by sqlite3_free(). (check-in: ac1f37a6 user: drh tags: malloc-enhancement) | |
11:28 | Experimental code to measure memory consumed by database schemas and prepared statements. (check-in: 9aa30342 user: dan tags: experimental) | |
2010-07-23
| ||
22:26 | Fix a typo in the OS/2 vfs code. (check-in: a6bb2108 user: drh tags: trunk) | |
17:37 | Merge two leaves. (check-in: 54e5886d user: dan tags: trunk) | |
Changes to src/alter.c.
︙ | |||
771 772 773 774 775 776 777 778 779 780 781 782 783 784 | 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 | + | pNew->nRef = 1; pNew->nCol = pTab->nCol; 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*)sqlite3DbMallocZero(db, sizeof(Column)*nAlloc); pNew->zName = sqlite3MPrintf(db, "sqlite_altertab_%s", pTab->zName); sqlite3MemLink(pNew, pNew->zName); if( !pNew->aCol || !pNew->zName ){ db->mallocFailed = 1; goto exit_begin_add_column; } memcpy(pNew->aCol, pTab->aCol, sizeof(Column)*pNew->nCol); for(i=0; i<pNew->nCol; i++){ Column *pCol = &pNew->aCol[i]; |
︙ |
Changes to src/analyze.c.
︙ | |||
482 483 484 485 486 487 488 | 482 483 484 485 486 487 488 489 490 491 492 493 494 495 | - - - - - - - - - - - - - - - - - - - - - - | } pIndex->aiRowEst[i] = v; if( *z==' ' ) z++; } return 0; } |
︙ | |||
538 539 540 541 542 543 544 | 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 | + + - + + + | assert( db->aDb[iDb].pBt!=0 ); assert( sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) ); /* Clear any prior statistics */ for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){ Index *pIdx = sqliteHashData(i); sqlite3DefaultRowEst(pIdx); if( pIdx->aSample ){ sqlite3MemUnlink(pIdx, pIdx->aSample); |
︙ | |||
584 585 586 587 588 589 590 591 | 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 | + - + - - + + - - - + + - + + - - - + + + | while( sqlite3_step(pStmt)==SQLITE_ROW ){ char *zIndex = (char *)sqlite3_column_text(pStmt, 0); Index *pIdx = sqlite3FindIndex(db, zIndex, sInfo.zDatabase); if( pIdx ){ int iSample = sqlite3_column_int(pStmt, 1); if( iSample<SQLITE_INDEX_SAMPLES && iSample>=0 ){ int eType = sqlite3_column_type(pStmt, 2); IndexSample *aSample = pIdx->aSample; |
︙ |
Changes to src/btree.c.
︙ | |||
2000 2001 2002 2003 2004 2005 2006 | 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 | - + | ** Clean out and delete the BtShared object. */ assert( !pBt->pCursor ); sqlite3PagerClose(pBt->pPager); if( pBt->xFreeSchema && pBt->pSchema ){ pBt->xFreeSchema(pBt->pSchema); } |
︙ | |||
7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 | 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 | + | } for(i=0; i<=sCheck.nPage; i++){ sCheck.anRef[i] = 0; } i = PENDING_BYTE_PAGE(pBt); if( i<=sCheck.nPage ){ sCheck.anRef[i] = 1; } sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), 20000); sCheck.errMsg.useMalloc = 2; /* Check the integrity of the freelist */ checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]), get4byte(&pBt->pPage1->aData[36]), "Main freelist: "); /* Check all the tables. |
︙ | |||
7882 7883 7884 7885 7886 7887 7888 | 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 | - + | ** blob of allocated memory. This function should not call sqlite3_free() ** on the memory, the btree layer does that. */ void *sqlite3BtreeSchema(Btree *p, int nBytes, void(*xFree)(void *)){ BtShared *pBt = p->pBt; sqlite3BtreeEnter(p); if( !pBt->pSchema && nBytes ){ |
︙ |
Changes to src/build.c.
︙ | |||
342 343 344 345 346 347 348 | 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | - - - - | return p; } /* ** Reclaim the memory used by an index */ static void freeIndex(sqlite3 *db, Index *p){ |
︙ | |||
474 475 476 477 478 479 480 | 470 471 472 473 474 475 476 477 478 479 480 481 482 483 | - - - | int i; Column *pCol; assert( pTable!=0 ); if( (pCol = pTable->aCol)!=0 ){ for(i=0; i<pTable->nCol; i++, pCol++){ sqlite3DbFree(db, pCol->zName); sqlite3ExprDelete(db, pCol->pDflt); |
︙ | |||
519 520 521 522 523 524 525 | 512 513 514 515 516 517 518 519 520 521 522 523 524 525 | - - | /* Delete any foreign keys attached to this table. */ sqlite3FkDelete(db, pTable); /* Delete the Table structure itself. */ sqliteResetColumnNames(db, pTable); |
︙ | |||
809 810 811 812 813 814 815 816 817 818 819 820 821 822 | 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 | + | if( pTable==0 ){ db->mallocFailed = 1; pParse->rc = SQLITE_NOMEM; pParse->nErr++; goto begin_table_error; } pTable->zName = zName; sqlite3MemLink(pTable, zName); pTable->iPKey = -1; pTable->pSchema = db->aDb[iDb].pSchema; pTable->nRef = 1; assert( pParse->pNewTable==0 ); pParse->pNewTable = pTable; /* If this is the magic sqlite_sequence table used by autoincrement, |
︙ | |||
941 942 943 944 945 946 947 | 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 | - + | sqlite3ErrorMsg(pParse, "duplicate column name: %s", z); sqlite3DbFree(db, z); return; } } if( (p->nCol & 0x7)==0 ){ Column *aNew; |
︙ | |||
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 | 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 | + | Column *pCol; p = pParse->pNewTable; if( p==0 || NEVER(p->nCol<1) ) return; pCol = &p->aCol[p->nCol-1]; assert( pCol->zType==0 ); pCol->zType = sqlite3NameFromToken(pParse->db, pType); sqlite3MemLink(p->aCol, pCol->zType); pCol->affinity = sqlite3AffinityType(pCol->zType); } /* ** The expression is the default value for the most recently added column ** of the table currently under construction. ** |
︙ | |||
1082 1083 1084 1085 1086 1087 1088 | 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 | - + | }else{ /* A copy of pExpr is used instead of the original, as pExpr contains ** tokens that point to volatile memory. The 'span' of the expression ** is required by pragma table_info. */ sqlite3ExprDelete(db, pCol->pDflt); pCol->pDflt = sqlite3ExprDup(db, pSpan->pExpr, EXPRDUP_REDUCE); |
︙ | |||
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 | 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 | + | db = pParse->db; zColl = sqlite3NameFromToken(db, pToken); if( !zColl ) return; if( sqlite3LocateCollSeq(pParse, zColl) ){ Index *pIdx; p->aCol[i].zColl = zColl; sqlite3MemLink(p->aCol, zColl); /* If the column is declared as "<name> PRIMARY KEY COLLATE <type>", ** then an index may have been created on this column before the ** collation type was added. Correct this if it is the case. */ for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){ assert( pIdx->nColumn==1 ); |
︙ | |||
1363 1364 1365 1366 1367 1368 1369 | 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 | - + | zEnd = ")"; }else{ zSep = "\n "; zSep2 = ",\n "; zEnd = "\n)"; } n += 35 + 6*p->nCol; |
︙ | |||
2809 2810 2811 2812 2813 2814 2815 | 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 | - - - + - | } pRet = pIndex; pIndex = 0; } /* Clean up before exiting */ exit_create_index: |
︙ |
Changes to src/callback.c.
︙ | |||
435 436 437 438 439 440 441 | 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 | - + | ** a new one if necessary. */ Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){ Schema * p; if( pBt ){ p = (Schema *)sqlite3BtreeSchema(pBt, sizeof(Schema), sqlite3SchemaFree); }else{ |
︙ |
Changes to src/func.c.
︙ | |||
1006 1007 1008 1009 1010 1011 1012 | 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 | - + - + | u8 *zOld; sqlite3 *db = sqlite3_context_db_handle(context); nOut += nRep - nPattern; testcase( nOut-1==db->aLimit[SQLITE_LIMIT_LENGTH] ); testcase( nOut-2==db->aLimit[SQLITE_LIMIT_LENGTH] ); if( nOut-1>db->aLimit[SQLITE_LIMIT_LENGTH] ){ sqlite3_result_error_toobig(context); |
︙ | |||
1374 1375 1376 1377 1378 1379 1380 | 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 | - + | assert( argc==1 || argc==2 ); if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum)); if( pAccum ){ sqlite3 *db = sqlite3_context_db_handle(context); int firstTerm = pAccum->useMalloc==0; |
︙ |
Changes to src/insert.c.
︙ | |||
63 64 65 66 67 68 69 | 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | - + | ** The column affinity string will eventually be deleted by ** sqliteDeleteIndex() when the Index structure itself is cleaned ** up. */ int n; Table *pTab = pIdx->pTable; sqlite3 *db = sqlite3VdbeDb(v); |
︙ | |||
105 106 107 108 109 110 111 | 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | - + - | ** sqlite3DeleteTable() when the Table structure itself is cleaned up. */ if( !pTab->zColAff ){ char *zColAff; int i; sqlite3 *db = sqlite3VdbeDb(v); |
︙ |
Changes to src/loadext.c.
︙ | |||
372 373 374 375 376 377 378 | 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | - + - - - + - - | if( zProc==0 ){ zProc = "sqlite3_extension_init"; } handle = sqlite3OsDlOpen(pVfs, zFile); if( handle==0 ){ if( pzErrMsg ){ |
︙ |
Changes to src/malloc.c.
︙ | |||
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | ************************************************************************* ** ** Memory allocation functions used throughout sqlite. */ #include "sqliteInt.h" #include <stdarg.h> /* ** There are two general-purpose memory allocators: ** ** Simple: ** ** sqlite3_malloc ** sqlite3_free ** sqlite3_realloc ** sqlite3Malloc ** sqlite3MallocSize ** sqlite3_mprintf ** ** Enhanced: ** ** sqlite3DbMallocRaw ** sqlite3DbMallocZero ** sqlite3DbFree ** sqlite3DbRealloc ** sqlite3MPrintf ** sqlite3DbMalloc ** ** All external allocations use the simple memory allocator. ** The enhanced allocator is used internally only, and is not ** available to extensions or applications. ** ** The enhanced allocator is a wrapper around the simple allocator that ** adds the following capabilities: ** ** (1) Access to lookaside memory associated with a database connection. ** ** (2) The ability to link allocations into a hierarchy with automatic ** deallocation of all elements of the subhierarchy whenever any ** element within the hierarchy is deallocated. ** ** The two allocators are incompatible in the sense that allocations that ** originate from the simple allocator must be deallocated using the simple ** deallocator and allocations that originate from the enhanced allocator must ** be deallocated using the enhanced deallocator. You cannot check-out ** memory from one allocator then return it to the other. */ /* ** The automatic hierarchical deallocation feature of the enhanced allocator ** is implemented by adding an instance of the following structure to the ** header of each enhanced allocation. ** ** In order to preserve alignment, this structure must be a multiple of ** 8 bytes in size. */ typedef struct EMemHdr EMemHdr; struct EMemHdr { EMemHdr *pEChild; /* List of children of this node */ EMemHdr *pESibling; /* Other nodes that are children of the same parent */ #ifdef SQLITE_MEMDEBUG u32 iEMemMagic; /* Magic number for sanity checking */ u32 isAChild; /* True if this allocate is a child of another */ #endif }; /* ** Macros for querying and setting debugging fields of the EMemHdr object. */ #ifdef SQLITE_MEMDEBUG # define isValidEMem(E) ((E)->iEMemMagic==0xc0a43fad) # define setValidEMem(E) (E)->iEMemMagic = 0xc0a43fad # define clearValidEMem(E) (E)->iEMemMagic = 0x12345678 # define isChildEMem(E) ((E)->isAChild!=0) # define notChildEMem(E) ((E)->isAChild==0) # define setChildEMem(E) (E)->isAChild = 1 # define clearChildEMem(E) (E)->isAChild = 0 #else # define isValidEMem(E) 1 # define setValidEMem(E) # define clearValidEMem(E) # define isChildEMem(E) 1 # define notChildEMem(E) 1 # define setChildEMem(E) # define clearChildEMem(E) #endif /* ** This routine runs when the memory allocator sees that the ** total memory allocation is about to exceed the soft heap ** limit. */ static void softHeapLimitEnforcer( void *NotUsed, sqlite3_int64 NotUsed2, int allocSize ){ UNUSED_PARAMETER2(NotUsed, NotUsed2); sqlite3_release_memory(allocSize); } /* ** Set the soft heap-size limit for the library. Passing a zero or ** negative value indicates no limit. ** ** If the total amount of memory allocated (by all threads) exceeds ** the soft heap limit, then sqlite3_release_memory() is invoked to ** try to free up some memory before proceeding. */ void sqlite3_soft_heap_limit(int n){ sqlite3_uint64 iLimit; int overage; if( n<0 ){ iLimit = 0; }else{ |
︙ | |||
364 365 366 367 368 369 370 371 372 373 374 375 376 377 | 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 | + | } void sqlite3ScratchFree(void *p){ if( p ){ if( sqlite3GlobalConfig.pScratch==0 || p<sqlite3GlobalConfig.pScratch || p>=(void*)mem0.aScratchFree ){ assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) ); assert( sqlite3MemdebugNoType(p, ~MEMTYPE_SCRATCH) ); sqlite3MemdebugSetType(p, MEMTYPE_HEAP); if( sqlite3GlobalConfig.bMemstat ){ int iSize = sqlite3MallocSize(p); sqlite3_mutex_enter(mem0.mutex); sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, -iSize); sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -iSize); sqlite3GlobalConfig.m.xFree(p); |
︙ | |||
413 414 415 416 417 418 419 420 421 422 423 424 | 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 | + + + + - + + + + + + - + + - + + - + + + + + - + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - + + + + | #else #define isLookaside(A,B) 0 #endif /* ** Return the size of a memory allocation previously obtained from ** sqlite3Malloc() or sqlite3_malloc(). ** ** The size returned is the usable size and does not include any ** bookkeeping overhead or sentinals at the end of the allocation. */ int sqlite3MallocSize(void *p){ assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); assert( sqlite3MemdebugNoType(p, MEMTYPE_RECURSIVE) ); return sqlite3GlobalConfig.m.xSize(p); } |
︙ | |||
493 494 495 496 497 498 499 500 501 502 503 504 505 506 | 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 | + | sqlite3_mutex_enter(mem0.mutex); sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, nBytes); if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)+nNew-nOld >= mem0.alarmThreshold ){ sqlite3MallocAlarm(nNew-nOld); } assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) ); assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) ); pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); if( pNew==0 && mem0.alarmCallback ){ sqlite3MallocAlarm(nBytes); pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); } if( pNew ){ nNew = sqlite3MallocSize(pNew); |
︙ | |||
533 534 535 536 537 538 539 | 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 | - + + + + + + + + + + + + + + + + - + + - + + - - + + + - - + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + - - + + - - + + + + - + + - - - - - - + + + + + + + + + | if( p ){ memset(p, 0, n); } return p; } /* |
︙ | |||
677 678 679 680 681 682 683 684 685 686 687 688 689 690 | 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | zNew = sqlite3DbMallocRaw(db, n+1); if( zNew ){ memcpy(zNew, z, n); zNew[n] = 0; } return zNew; } /* ** Link extended allocation nodes such that deallocating the parent ** causes the child to be automatically deallocated. */ void sqlite3MemLink(void *pParentObj, void *pChildObj){ EMemHdr *pParent = (EMemHdr*)pParentObj; EMemHdr *pChild = (EMemHdr*)pChildObj; if( pParent && pChild ){ pParent--; assert( isValidEMem(pParent) ); /* pParentObj is an extended allocation */ pChild--; assert( isValidEMem(pChild) ); /* pChildObj is an extended allocation */ assert( notChildEMem(pChild) ); /* pChildObj not a child of another obj */ pChild->pESibling = pParent->pEChild; pParent->pEChild = pChild; setChildEMem(pChild); } } /* ** pChildObj is a child object of pParentObj due to a prior call ** to sqlite3MemLink(). This routine breaks that linkage, making ** pChildObj an independent node that is not a child of any other node. */ void sqlite3MemUnlink(void *pParentObj, void *pChildObj){ EMemHdr *pParent = (EMemHdr*)pParentObj; EMemHdr *pChild = (EMemHdr*)pChildObj; EMemHdr **pp; assert( pParentObj!=0 ); assert( pChildObj!=0 ); pParent--; assert( isValidEMem(pParent) ); /* pParentObj is an extended allocation */ pChild--; assert( isValidEMem(pChild) ); /* pChildObj is an extended allocation */ assert( isChildEMem(pChild) ); /* pChildObj a child of something */ for(pp=&pParent->pEChild; (*pp)!=pChild; pp = &(*pp)->pESibling){ assert( *pp ); /* pChildObj is a child of pParentObj */ assert( isValidEMem(*pp) ); /* All children of pParentObj are valid */ assert( isChildEMem(*pp) ); /* All children of pParentObj are children */ } *pp = pChild->pESibling; pChild->pESibling = 0; clearChildEMem(pChild); } /* ** Create a string from the zFromat argument and the va_list that follows. ** Store the string in memory obtained from sqliteMalloc() and make *pz ** point to that string. */ void sqlite3SetString(char **pz, sqlite3 *db, const char *zFormat, ...){ |
︙ |
Changes to src/mem2.c.
︙ | |||
397 398 399 400 401 402 403 | 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 | - - - - - - + + + + + + + + + + + + + + + + + + + + + | */ int sqlite3MemdebugHasType(void *p, u8 eType){ int rc = 1; if( p ){ struct MemBlockHdr *pHdr; pHdr = sqlite3MemsysGetHeader(p); assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */ |
︙ |
Changes to src/notify.c.
︙ | |||
251 252 253 254 255 256 257 | 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | - + | nArg = 0; } sqlite3BeginBenignMalloc(); assert( aArg==aDyn || (aDyn==0 && aArg==aStatic) ); assert( nArg<=(int)ArraySize(aStatic) || aArg==aDyn ); if( (!aDyn && nArg==(int)ArraySize(aStatic)) |
︙ |
Changes to src/pragma.c.
︙ | |||
761 762 763 764 765 766 767 | 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 | - + | || (SQLITE_TEMP_STORE==1 && db->temp_store<=1) || (SQLITE_TEMP_STORE==2 && db->temp_store==1) ){ invalidateTempStorage(pParse); } sqlite3_free(sqlite3_temp_directory); if( zRight[0] ){ |
︙ |
Changes to src/printf.c.
︙ | |||
768 769 770 771 772 773 774 | 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 | + - + + + + | if( szNew > p->mxAlloc ){ sqlite3StrAccumReset(p); p->tooBig = 1; return; }else{ p->nAlloc = (int)szNew; } if( p->useMalloc==1 ){ |
︙ | |||
793 794 795 796 797 798 799 | 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 | + - + + + + + - + + + + | ** Return a pointer to the resulting string. Return a NULL ** pointer if any kind of error was encountered. */ char *sqlite3StrAccumFinish(StrAccum *p){ if( p->zText ){ p->zText[p->nChar] = 0; if( p->useMalloc && p->zText==p->zBase ){ if( p->useMalloc==1 ){ |
︙ | |||
891 892 893 894 895 896 897 898 899 900 901 902 903 904 | 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 | + | char *z; char zBase[SQLITE_PRINT_BUF_SIZE]; StrAccum acc; #ifndef SQLITE_OMIT_AUTOINIT if( sqlite3_initialize() ) return 0; #endif sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH); acc.useMalloc = 2; sqlite3VXPrintf(&acc, 0, zFormat, ap); z = sqlite3StrAccumFinish(&acc); return z; } /* ** Print into memory obtained from sqlite3_malloc()(). Omit the internal |
︙ |
Changes to src/select.c.
︙ | |||
1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 | 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 | + + | if( db->mallocFailed ) return; memset(&sNC, 0, sizeof(sNC)); sNC.pSrcList = pSelect->pSrc; a = pSelect->pEList->a; for(i=0, pCol=aCol; i<nCol; i++, pCol++){ p = a[i].pExpr; pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p, 0, 0, 0)); sqlite3MemLink(aCol, pCol->zType); pCol->affinity = sqlite3ExprAffinity(p); if( pCol->affinity==0 ) pCol->affinity = SQLITE_AFF_NONE; pColl = sqlite3ExprCollSeq(pParse, p); if( pColl ){ pCol->zColl = sqlite3DbStrDup(db, pColl->zName); sqlite3MemLink(aCol, pCol->zColl); } } } /* ** Given a SELECT statement, generate a Table structure that describes ** the result set of that SELECT. |
︙ | |||
3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 | 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 | + | assert( pSel!=0 ); assert( pFrom->pTab==0 ); sqlite3WalkSelect(pWalker, pSel); pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table)); if( pTab==0 ) return WRC_Abort; pTab->nRef = 1; pTab->zName = sqlite3MPrintf(db, "sqlite_subquery_%p_", (void*)pTab); sqlite3MemLink(pTab, pTab->zName); while( pSel->pPrior ){ pSel = pSel->pPrior; } selectColumnsFromExprList(pParse, pSel->pEList, &pTab->nCol, &pTab->aCol); pTab->iPKey = -1; pTab->tabFlags |= TF_Ephemeral; #endif }else{ /* An ordinary table or view name in the FROM clause */ |
︙ |
Changes to src/sqliteInt.h.
︙ | |||
2321 2322 2323 2324 2325 2326 2327 | 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 | - + | sqlite3 *db; /* Optional database for lookaside. Can be NULL */ char *zBase; /* A base allocation. Not from malloc. */ char *zText; /* The string collected so far */ int nChar; /* Length of the string so far */ int nAlloc; /* Amount of space allocated in zText */ int mxAlloc; /* Maximum allowed string length */ u8 mallocFailed; /* Becomes true if any memory allocation fails */ |
︙ | |||
2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 | 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 | + + + + | int sqlite3MallocInit(void); void sqlite3MallocEnd(void); void *sqlite3Malloc(int); void *sqlite3MallocZero(int); void *sqlite3DbMallocZero(sqlite3*, int); void *sqlite3DbMallocRaw(sqlite3*, int); void *sqlite3DbMallocZeroChild(sqlite3*, int, void *pParent); void *sqlite3DbMallocRawChild(sqlite3*, int, void *pParent); char *sqlite3DbStrDup(sqlite3*,const char*); char *sqlite3DbStrNDup(sqlite3*,const char*, int); void *sqlite3Realloc(void*, int); void *sqlite3DbReallocOrFree(sqlite3 *, void *, int); void *sqlite3DbRealloc(sqlite3 *, void *, int); void sqlite3DbFree(sqlite3*, void*); void sqlite3MemLink(void *pParent, void *pChild); void sqlite3MemUnlink(void *pParent, void *pChild); int sqlite3MallocSize(void*); int sqlite3DbMallocSize(sqlite3*, void*); void *sqlite3ScratchMalloc(int); void sqlite3ScratchFree(void*); void *sqlite3PageMalloc(int); void sqlite3PageFree(void*); void sqlite3MemSetDefault(void); |
︙ | |||
2904 2905 2906 2907 2908 2909 2910 | 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 | - | CollSeq *sqlite3GetCollSeq(sqlite3*, u8, CollSeq *, const char*); char sqlite3AffinityType(const char*); void sqlite3Analyze(Parse*, Token*, Token*); int sqlite3InvokeBusyHandler(BusyHandler*); int sqlite3FindDb(sqlite3*, Token*); int sqlite3FindDbName(sqlite3 *, const char *); int sqlite3AnalysisLoad(sqlite3*,int iDB); |
︙ | |||
3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 | 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 | + + + + + + - - - - + + + + + | ** sqlite3MemdebugSetType() sets the "type" of an allocation to one of ** the MEMTYPE_* macros defined below. The type must be a bitmask with ** a single bit set. ** ** sqlite3MemdebugHasType() returns true if any of the bits in its second ** argument match the type set by the previous sqlite3MemdebugSetType(). ** sqlite3MemdebugHasType() is intended for use inside assert() statements. ** ** sqlite3MemdebugNoType() returns true if none of the bits in its second ** argument match the type set by the previous sqlite3MemdebugSetType(). ** ** For example: ** ** assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); ** ** Perhaps the most important point is the difference between MEMTYPE_HEAP ** and MEMTYPE_DB. If an allocation is MEMTYPE_DB, that means it might have ** been allocated by lookaside, except the allocation was too large or ** lookaside was already full. It is important to verify that allocations ** that might have been satisfied by lookaside are not passed back to ** non-lookaside free() routines. Asserts such as the example above are ** placed on the non-lookaside free() routines to verify this constraint. ** ** All of this is no-op for a production build. It only comes into ** play when the SQLITE_MEMDEBUG compile-time option is used. */ #ifdef SQLITE_MEMDEBUG void sqlite3MemdebugSetType(void*,u8); int sqlite3MemdebugHasType(void*,u8); int sqlite3MemdebugNoType(void*,u8); #else # define sqlite3MemdebugSetType(X,Y) /* no-op */ # define sqlite3MemdebugHasType(X,Y) 1 # define sqlite3MemdebugNoType(X,Y) 1 #endif |
Changes to src/test4.c.
︙ | |||
138 139 140 141 142 143 144 | 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | - + | if( i<0 ) return TCL_ERROR; if( threadset[i].busy ){ Tcl_AppendResult(interp, "thread ", argv[1], " is already running", 0); return TCL_ERROR; } threadset[i].busy = 1; sqlite3_free(threadset[i].zFilename); |
︙ | |||
472 473 474 475 476 477 478 | 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | - + | if( !threadset[i].busy ){ Tcl_AppendResult(interp, "no such thread", 0); return TCL_ERROR; } thread_wait(&threadset[i]); threadset[i].xOp = do_compile; sqlite3_free(threadset[i].zArg); |
︙ |
Changes to src/test5.c.
︙ | |||
151 152 153 154 155 156 157 | 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | - + | if( !enc_to ) return TCL_ERROR; pVal = sqlite3ValueNew(0); if( enc_from==SQLITE_UTF8 ){ z = Tcl_GetString(objv[1]); if( objc==5 ){ |
︙ |
Changes to src/test7.c.
︙ | |||
160 161 162 163 164 165 166 | 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | - + | if( i<0 ) return TCL_ERROR; if( threadset[i].busy ){ Tcl_AppendResult(interp, "thread ", argv[1], " is already running", 0); return TCL_ERROR; } threadset[i].busy = 1; sqlite3_free(threadset[i].zFilename); |
︙ | |||
503 504 505 506 507 508 509 | 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 | - + | if( !threadset[i].busy ){ Tcl_AppendResult(interp, "no such thread", 0); return TCL_ERROR; } client_wait(&threadset[i]); threadset[i].xOp = do_compile; sqlite3_free(threadset[i].zArg); |
︙ |
Changes to src/test8.c.
︙ | |||
481 482 483 484 485 486 487 | 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 | - + | char *zSql; echo_vtab *pVtab = *(echo_vtab **)ppVtab; pVtab->zLogName = sqlite3_mprintf("%s", argv[4]); zSql = sqlite3_mprintf("CREATE TABLE %Q(logmsg)", pVtab->zLogName); rc = sqlite3_exec(db, zSql, 0, 0, 0); sqlite3_free(zSql); if( rc!=SQLITE_OK ){ |
︙ |
Changes to src/tokenize.c.
︙ | |||
492 493 494 495 496 497 498 | 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | - + | if( pParse->nested==0 ){ sqlite3DbFree(db, pParse->aTableLock); pParse->aTableLock = 0; pParse->nTableLock = 0; } #endif #ifndef SQLITE_OMIT_VIRTUALTABLE |
︙ |
Changes to src/vdbe.c.
︙ | |||
496 497 498 499 500 501 502 503 504 505 506 507 508 509 | 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 | + + + + + + + + + + + + + + | int n = 0; Savepoint *p; for(p=db->pSavepoint; p; p=p->pNext) n++; assert( n==(db->nSavepoint + db->isTransactionSavepoint) ); return 1; } #endif /* ** Transfer error message text from an sqlite3_vtab.zErrMsg (text stored ** in memory obtained from sqlite3_malloc) into a Vdbe.zErrMsg (text stored ** in memory obtained from sqlite3DbMalloc). */ static void importVtabErrMsg(Vdbe *p, sqlite3_vtab *pVtab){ sqlite3 *db = p->db; sqlite3DbFree(db, p->zErrMsg); p->zErrMsg = sqlite3DbStrDup(db, pVtab->zErrMsg); sqlite3_free(pVtab->zErrMsg); pVtab->zErrMsg = 0; } /* ** Execute as much of a VDBE program as we can then return. ** ** sqlite3VdbeMakeReady() must be called before this routine in order to ** close the program with a final OP_Halt and to set up the callbacks ** and the error message pointer. |
︙ | |||
4026 4027 4028 4029 4030 4031 4032 | 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 | - - - + | v = pC->movetoTarget; #ifndef SQLITE_OMIT_VIRTUALTABLE }else if( pC->pVtabCursor ){ pVtab = pC->pVtabCursor->pVtab; pModule = pVtab->pModule; assert( pModule->xRowid ); rc = pModule->xRowid(pC->pVtabCursor, &v); |
︙ | |||
5371 5372 5373 5374 5375 5376 5377 | 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 | - + - - - - | ** within a callback to a virtual table xSync() method. If it is, the error ** code will be set to SQLITE_LOCKED. */ case OP_VBegin: { VTable *pVTab; pVTab = pOp->p4.pVtab; rc = sqlite3VtabBegin(db, pVTab); |
︙ | |||
5425 5426 5427 5428 5429 5430 5431 | 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 | - - - + | pCur = 0; pVtabCursor = 0; pVtab = pOp->p4.pVtab->pVtab; pModule = (sqlite3_module *)pVtab->pModule; assert(pVtab && pModule); rc = pModule->xOpen(pVtab, &pVtabCursor); |
︙ | |||
5504 5505 5506 5507 5508 5509 5510 | 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 | - - - + | apArg[i] = &pArgc[i+1]; sqlite3VdbeMemStoreType(apArg[i]); } p->inVtabMethod = 1; rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg); p->inVtabMethod = 0; |
︙ | |||
5556 5557 5558 5559 5560 5561 5562 | 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 | - - - + | ** can use the already allocated buffer instead of allocating a ** new one. */ sqlite3VdbeMemMove(&sContext.s, pDest); MemSetTypeFlag(&sContext.s, MEM_Null); rc = pModule->xColumn(pCur->pVtabCursor, &sContext, pOp->p2); |
︙ | |||
5611 5612 5613 5614 5615 5616 5617 | 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 | - - - + | ** xNext(). Instead, if an error occurs, true is returned (indicating that ** data is available) and the error code returned when xColumn or ** some other method is next invoked on the save virtual table cursor. */ p->inVtabMethod = 1; rc = pModule->xNext(pCur->pVtabCursor); p->inVtabMethod = 0; |
︙ | |||
5643 5644 5645 5646 5647 5648 5649 | 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 | - - - + | pVtab = pOp->p4.pVtab->pVtab; pName = &aMem[pOp->p1]; assert( pVtab->pModule->xRename ); REGISTER_TRACE(pOp->p1, pName); assert( pName->flags & MEM_Str ); rc = pVtab->pModule->xRename(pVtab, pName->z); |
︙ | |||
5697 5698 5699 5700 5701 5702 5703 | 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 | - - - + | pX = &aMem[pOp->p3]; for(i=0; i<nArg; i++){ sqlite3VdbeMemStoreType(pX); apArg[i] = pX; pX++; } rc = pModule->xUpdate(pVtab, nArg, apArg, &rowid); |
︙ |
Changes to src/vdbeaux.c.
︙ | |||
577 578 579 580 581 582 583 | 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 | - + + + + | ** Delete a P4 value if necessary. */ static void freeP4(sqlite3 *db, int p4type, void *p4){ if( p4 ){ switch( p4type ){ case P4_REAL: case P4_INT64: |
︙ | |||
735 736 737 738 739 740 741 | 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 | - + | pOp->p4type = P4_NOTUSED; }else if( n==P4_KEYINFO ){ KeyInfo *pKeyInfo; int nField, nByte; nField = ((KeyInfo*)zP4)->nField; nByte = sizeof(*pKeyInfo) + (nField-1)*sizeof(pKeyInfo->aColl[0]) + nField; |
︙ |
Changes to src/vtab.c.
︙ | |||
462 463 464 465 466 467 468 | 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 | - + | if( rc==SQLITE_NOMEM ) db->mallocFailed = 1; if( SQLITE_OK!=rc ){ if( zErr==0 ){ *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName); }else { *pzErr = sqlite3MPrintf(db, "%s", zErr); |
︙ | |||
669 670 671 672 673 674 675 | 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 | - + | pTab->nCol = pParse->pNewTable->nCol; pParse->pNewTable->nCol = 0; pParse->pNewTable->aCol = 0; } db->pVTab = 0; }else{ sqlite3Error(db, SQLITE_ERROR, zErr); |
︙ | |||
764 765 766 767 768 769 770 | 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 | - - + + | db->aVTrans = 0; for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){ int (*x)(sqlite3_vtab *); sqlite3_vtab *pVtab = aVTrans[i]->pVtab; if( pVtab && (x = pVtab->pModule->xSync)!=0 ){ rc = x(pVtab); sqlite3DbFree(db, *pzErrmsg); |
︙ |
Changes to src/where.c.
︙ | |||
2021 2022 2023 2024 2025 2026 2027 | 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 | - + | pParse->db->mallocFailed = 1; }else if( !pVtab->zErrMsg ){ sqlite3ErrorMsg(pParse, "%s", sqlite3ErrStr(rc)); }else{ sqlite3ErrorMsg(pParse, "%s", pVtab->zErrMsg); } } |
︙ | |||
3801 3802 3803 3804 3805 3806 3807 | 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 | - - - + - | if( pInfo->needToFreeIdxStr ){ sqlite3_free(pInfo->idxStr); } sqlite3DbFree(db, pInfo); } if( pWInfo->a[i].plan.wsFlags & WHERE_TEMP_INDEX ){ Index *pIdx = pWInfo->a[i].plan.u.pIdx; |
︙ |