/ Check-in [714254cb]
Login

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

Overview
Comment:Fix a memory leak: a failure to deallocate the P3 parameter on a call to sqlite3VdbeChangeP3. (CVS 2695)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 714254cbc12564d44548707043fdcdffb17e4fde
User & Date: drh 2005-09-16 00:27:01
Context
2005-09-16
02:38
Fix a whole host of newly discovered memory leaks the occur after a failure of realloc(). (CVS 2696) check-in: 4686d649 user: drh tags: trunk
00:27
Fix a memory leak: a failure to deallocate the P3 parameter on a call to sqlite3VdbeChangeP3. (CVS 2695) check-in: 714254cb user: drh tags: trunk
2005-09-15
21:24
The table_info pragma now gives the order of columns in the primary key. (CVS 2694) check-in: 9b60f48d user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/vdbeaux.c.

64
65
66
67
68
69
70

71
72

73
74
75
76
77
78
79
80
...
343
344
345
346
347
348
349





















350
351
352
353
354
355
356
...
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
....
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
static void resizeOpArray(Vdbe *p, int N){
  if( p->magic==VDBE_MAGIC_RUN ){
    assert( N==p->nOp );
    p->nOpAlloc = N;
    p->aOp = sqliteRealloc(p->aOp, N*sizeof(Op));
  }else if( p->nOpAlloc<N ){
    int oldSize = p->nOpAlloc;

    p->nOpAlloc = N+100;
    p->aOp = sqliteRealloc(p->aOp, p->nOpAlloc*sizeof(Op));

    if( p->aOp ){
      memset(&p->aOp[oldSize], 0, (p->nOpAlloc-oldSize)*sizeof(Op));
    }
  }
}

/*
** Add a new instruction to the list of instructions current in the
................................................................................
void sqlite3VdbeChangeP2(Vdbe *p, int addr, int val){
  assert( val>=0 );
  assert( p->magic==VDBE_MAGIC_INIT );
  if( p && addr>=0 && p->nOp>addr && p->aOp ){
    p->aOp[addr].p2 = val;
  }
}






















/*
** Change the value of the P3 operand for a specific instruction.
** This routine is useful when a large program is loaded from a
** static array using sqlite3VdbeAddOpList but we want to make a
** few minor changes to the program.
**
................................................................................
**
** If addr<0 then change P3 on the most recently inserted instruction.
*/
void sqlite3VdbeChangeP3(Vdbe *p, int addr, const char *zP3, int n){
  Op *pOp;
  assert( p->magic==VDBE_MAGIC_INIT );
  if( p==0 || p->aOp==0 ){
    if( n==P3_DYNAMIC || n==P3_KEYINFO_HANDOFF ){
      sqliteFree((void*)zP3);
    }
    if( n==P3_MEM ){
      sqlite3ValueFree((sqlite3_value *)zP3);
    }
    return;
  }
  if( addr<0 || addr>=p->nOp ){
    addr = p->nOp - 1;
    if( addr<0 ) return;
  }
  pOp = &p->aOp[addr];
  if( pOp->p3 && pOp->p3type==P3_DYNAMIC ){
    sqliteFree(pOp->p3);
    pOp->p3 = 0;
  }
  if( zP3==0 ){
    pOp->p3 = 0;
    pOp->p3type = P3_NOTUSED;
  }else if( n==P3_KEYINFO ){
    KeyInfo *pKeyInfo;
    int nField, nByte;

................................................................................
  }
  if( p->pNext ){
    p->pNext->pPrev = p->pPrev;
  }
  if( p->aOp ){
    for(i=0; i<p->nOp; i++){
      Op *pOp = &p->aOp[i];
      if( pOp->p3type==P3_DYNAMIC || pOp->p3type==P3_KEYINFO ){
        sqliteFree(pOp->p3);
      }
      if( pOp->p3type==P3_VDBEFUNC ){
        VdbeFunc *pVdbeFunc = (VdbeFunc *)pOp->p3;
        sqlite3VdbeDeleteAuxData(pVdbeFunc, 0);
        sqliteFree(pVdbeFunc);
      }
      if( pOp->p3type==P3_MEM ){
        sqlite3ValueFree((sqlite3_value*)pOp->p3);
      }
    }
    sqliteFree(p->aOp);
  }
  releaseMemArray(p->aVar, p->nVar);
  sqliteFree(p->aLabel);
  sqliteFree(p->aStack);
  releaseMemArray(p->aColName, p->nResColumn*2);







>

|
>
|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
<
<
<
<
<







|
<
|
<







 







<
<
<
<
<
<
<
<
|
<
<







64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
...
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
...
396
397
398
399
400
401
402
403





404
405
406
407
408
409
410
411

412

413
414
415
416
417
418
419
....
1343
1344
1345
1346
1347
1348
1349








1350


1351
1352
1353
1354
1355
1356
1357
static void resizeOpArray(Vdbe *p, int N){
  if( p->magic==VDBE_MAGIC_RUN ){
    assert( N==p->nOp );
    p->nOpAlloc = N;
    p->aOp = sqliteRealloc(p->aOp, N*sizeof(Op));
  }else if( p->nOpAlloc<N ){
    int oldSize = p->nOpAlloc;
    VdbeOp *pNew;
    p->nOpAlloc = N+100;
    pNew = sqliteRealloc(p->aOp, p->nOpAlloc*sizeof(Op));
    if( pNew ){
      p->aOp = pNew;
      memset(&p->aOp[oldSize], 0, (p->nOpAlloc-oldSize)*sizeof(Op));
    }
  }
}

/*
** Add a new instruction to the list of instructions current in the
................................................................................
void sqlite3VdbeChangeP2(Vdbe *p, int addr, int val){
  assert( val>=0 );
  assert( p->magic==VDBE_MAGIC_INIT );
  if( p && addr>=0 && p->nOp>addr && p->aOp ){
    p->aOp[addr].p2 = val;
  }
}


/*
** Delete a P3 value if necessary.
*/
static void freeP3(int p3type, void *p3){
  if( p3 ){
    if( p3type==P3_DYNAMIC || p3type==P3_KEYINFO ){
      sqliteFree(p3);
    }
    if( p3type==P3_VDBEFUNC ){
      VdbeFunc *pVdbeFunc = (VdbeFunc *)p3;
      sqlite3VdbeDeleteAuxData(pVdbeFunc, 0);
      sqliteFree(pVdbeFunc);
    }
    if( p3type==P3_MEM ){
      sqlite3ValueFree((sqlite3_value*)p3);
    }
  }
}


/*
** Change the value of the P3 operand for a specific instruction.
** This routine is useful when a large program is loaded from a
** static array using sqlite3VdbeAddOpList but we want to make a
** few minor changes to the program.
**
................................................................................
**
** If addr<0 then change P3 on the most recently inserted instruction.
*/
void sqlite3VdbeChangeP3(Vdbe *p, int addr, const char *zP3, int n){
  Op *pOp;
  assert( p->magic==VDBE_MAGIC_INIT );
  if( p==0 || p->aOp==0 ){
    freeP3(n, (void*)*(char**)&zP3);





    return;
  }
  if( addr<0 || addr>=p->nOp ){
    addr = p->nOp - 1;
    if( addr<0 ) return;
  }
  pOp = &p->aOp[addr];
  freeP3(pOp->p3type, pOp->p3);

  pOp->p3 = 0;

  if( zP3==0 ){
    pOp->p3 = 0;
    pOp->p3type = P3_NOTUSED;
  }else if( n==P3_KEYINFO ){
    KeyInfo *pKeyInfo;
    int nField, nByte;

................................................................................
  }
  if( p->pNext ){
    p->pNext->pPrev = p->pPrev;
  }
  if( p->aOp ){
    for(i=0; i<p->nOp; i++){
      Op *pOp = &p->aOp[i];








      freeP3(pOp->p3type, pOp->p3);


    }
    sqliteFree(p->aOp);
  }
  releaseMemArray(p->aVar, p->nVar);
  sqliteFree(p->aLabel);
  sqliteFree(p->aStack);
  releaseMemArray(p->aColName, p->nResColumn*2);