/ Check-in [305b6667]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Replace a few sqlite3_malloc()+memset() sequences with calls to sqlite3MallocZero().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 305b6667265353b858b79bfea1745e64ff3bb7d3
User & Date: dan 2012-07-30 14:53:54
References
2012-08-07
15:19
Fix a bug in hash.c introduced by [305b66672653]. check-in: 17cb5e95 user: dan tags: trunk
Context
2012-07-31
00:43
Modify metadata for the VSIX package and add tooling support for PDBs. check-in: 12cbf6a9 user: mistachkin tags: trunk
2012-07-30
14:53
Replace a few sqlite3_malloc()+memset() sequences with calls to sqlite3MallocZero(). check-in: 305b6667 user: dan tags: trunk
2012-07-27
23:03
Improve consistency in handling of build outputs and native library paths in the multi-platform build tool for MSVC. check-in: e71f2de2 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/analyze.c.

   252    252     int mxSample;
   253    253     int n;
   254    254   
   255    255     UNUSED_PARAMETER(argc);
   256    256     nRow = (tRowcnt)sqlite3_value_int64(argv[0]);
   257    257     mxSample = sqlite3_value_int(argv[1]);
   258    258     n = sizeof(*p) + sizeof(p->a[0])*mxSample;
   259         -  p = sqlite3_malloc( n );
          259  +  p = sqlite3MallocZero( n );
   260    260     if( p==0 ){
   261    261       sqlite3_result_error_nomem(context);
   262    262       return;
   263    263     }
   264         -  memset(p, 0, n);
   265    264     p->a = (struct Stat3Sample*)&p[1];
   266    265     p->nRow = nRow;
   267    266     p->mxSample = mxSample;
   268    267     p->nPSample = p->nRow/(mxSample/3+1) + 1;
   269    268     sqlite3_randomness(sizeof(p->iPrn), &p->iPrn);
   270    269     sqlite3_result_blob(context, p, sizeof(p), sqlite3_free);
   271    270   }

Changes to src/backup.c.

   160    160       );
   161    161       p = 0;
   162    162     }else {
   163    163       /* Allocate space for a new sqlite3_backup object...
   164    164       ** EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
   165    165       ** call to sqlite3_backup_init() and is destroyed by a call to
   166    166       ** sqlite3_backup_finish(). */
   167         -    p = (sqlite3_backup *)sqlite3_malloc(sizeof(sqlite3_backup));
          167  +    p = (sqlite3_backup *)sqlite3MallocZero(sizeof(sqlite3_backup));
   168    168       if( !p ){
   169    169         sqlite3Error(pDestDb, SQLITE_NOMEM, 0);
   170    170       }
   171    171     }
   172    172   
   173    173     /* If the allocation succeeded, populate the new object. */
   174    174     if( p ){
   175         -    memset(p, 0, sizeof(sqlite3_backup));
   176    175       p->pSrc = findBtree(pDestDb, pSrcDb, zSrcDb);
   177    176       p->pDest = findBtree(pDestDb, pDestDb, zDestDb);
   178    177       p->pDestDb = pDestDb;
   179    178       p->pSrcDb = pSrcDb;
   180    179       p->iNext = 1;
   181    180       p->isAttached = 0;
   182    181   

Changes to src/bitvec.c.

   336    336     int rc = -1;
   337    337     int i, nx, pc, op;
   338    338     void *pTmpSpace;
   339    339   
   340    340     /* Allocate the Bitvec to be tested and a linear array of
   341    341     ** bits to act as the reference */
   342    342     pBitvec = sqlite3BitvecCreate( sz );
   343         -  pV = sqlite3_malloc( (sz+7)/8 + 1 );
          343  +  pV = sqlite3MallocZero( (sz+7)/8 + 1 );
   344    344     pTmpSpace = sqlite3_malloc(BITVEC_SZ);
   345    345     if( pBitvec==0 || pV==0 || pTmpSpace==0  ) goto bitvec_end;
   346         -  memset(pV, 0, (sz+7)/8 + 1);
   347    346   
   348    347     /* NULL pBitvec tests */
   349    348     sqlite3BitvecSet(0, 1);
   350    349     sqlite3BitvecClear(0, 1, pTmpSpace);
   351    350   
   352    351     /* Run the program */
   353    352     pc = 0;

Changes to src/hash.c.

   112    112   #endif
   113    113   
   114    114     /* The inability to allocates space for a larger hash table is
   115    115     ** a performance hit but it is not a fatal error.  So mark the
   116    116     ** allocation as a benign.
   117    117     */
   118    118     sqlite3BeginBenignMalloc();
   119         -  new_ht = (struct _ht *)sqlite3Malloc( new_size*sizeof(struct _ht) );
          119  +  new_ht = (struct _ht *)sqlite3MallocZero( new_size*sizeof(struct _ht) );
   120    120     sqlite3EndBenignMalloc();
   121    121   
   122    122     if( new_ht==0 ) return 0;
   123    123     sqlite3_free(pH->ht);
   124    124     pH->ht = new_ht;
   125    125     pH->htsize = new_size = sqlite3MallocSize(new_ht)/sizeof(struct _ht);
   126         -  memset(new_ht, 0, new_size*sizeof(struct _ht));
   127    126     for(elem=pH->first, pH->first=0; elem; elem = next_elem){
   128    127       unsigned int h = strHash(elem->pKey, elem->nKey) % new_size;
   129    128       next_elem = elem->next;
   130    129       insertElement(pH, &new_ht[h], elem);
   131    130     }
   132    131     return 1;
   133    132   }

Changes to src/pcache1.c.

   392    392     nNew = p->nHash*2;
   393    393     if( nNew<256 ){
   394    394       nNew = 256;
   395    395     }
   396    396   
   397    397     pcache1LeaveMutex(p->pGroup);
   398    398     if( p->nHash ){ sqlite3BeginBenignMalloc(); }
   399         -  apNew = (PgHdr1 **)sqlite3_malloc(sizeof(PgHdr1 *)*nNew);
          399  +  apNew = (PgHdr1 **)sqlite3MallocZero(sizeof(PgHdr1 *)*nNew);
   400    400     if( p->nHash ){ sqlite3EndBenignMalloc(); }
   401    401     pcache1EnterMutex(p->pGroup);
   402    402     if( apNew ){
   403         -    memset(apNew, 0, sizeof(PgHdr1 *)*nNew);
   404    403       for(i=0; i<p->nHash; i++){
   405    404         PgHdr1 *pPage;
   406    405         PgHdr1 *pNext = p->apHash[i];
   407    406         while( (pPage = pNext)!=0 ){
   408    407           unsigned int h = pPage->iKey % nNew;
   409    408           pNext = pPage->pNext;
   410    409           pPage->pNext = apNew[h];
................................................................................
   580    579     int separateCache = sqlite3GlobalConfig.bCoreMutex>0;
   581    580   #endif
   582    581   
   583    582     assert( (szPage & (szPage-1))==0 && szPage>=512 && szPage<=65536 );
   584    583     assert( szExtra < 300 );
   585    584   
   586    585     sz = sizeof(PCache1) + sizeof(PGroup)*separateCache;
   587         -  pCache = (PCache1 *)sqlite3_malloc(sz);
          586  +  pCache = (PCache1 *)sqlite3MallocZero(sz);
   588    587     if( pCache ){
   589         -    memset(pCache, 0, sz);
   590    588       if( separateCache ){
   591    589         pGroup = (PGroup*)&pCache[1];
   592    590         pGroup->mxPinned = 10;
   593    591       }else{
   594    592         pGroup = &pcache1.grp;
   595    593       }
   596    594       pCache->pGroup = pGroup;

Changes to src/vdbetrace.c.

   165    165   /*
   166    166   ** Allocate a new Explain object
   167    167   */
   168    168   void sqlite3ExplainBegin(Vdbe *pVdbe){
   169    169     if( pVdbe ){
   170    170       Explain *p;
   171    171       sqlite3BeginBenignMalloc();
   172         -    p = sqlite3_malloc( sizeof(Explain) );
          172  +    p = (Explain *)sqlite3MallocZero( sizeof(Explain) );
   173    173       if( p ){
   174         -      memset(p, 0, sizeof(*p));
   175    174         p->pVdbe = pVdbe;
   176    175         sqlite3_free(pVdbe->pExplain);
   177    176         pVdbe->pExplain = p;
   178    177         sqlite3StrAccumInit(&p->str, p->zBase, sizeof(p->zBase),
   179    178                             SQLITE_MAX_LENGTH);
   180    179         p->str.useMalloc = 2;
   181    180       }else{