SQLite

Check-in [767ccb1fa1]
Login

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

Overview
Comment:Fix a potential memory use-after-free problem following an OOM error.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 767ccb1fa11b3e7b895fb8c2e91f79e3b4202907
User & Date: drh 2014-03-04 18:06:04.531
Context
2014-03-04
21:00
Fix a problem with "DEFAULT (-(-9223372036854775808))" clauses in ALTER TABLE ... ADD COLUMN commands. (check-in: e072cb3ee2 user: dan tags: trunk)
18:06
Fix a potential memory use-after-free problem following an OOM error. (check-in: 767ccb1fa1 user: drh tags: trunk)
16:21
Fix an assert() so that it takes OOM errors into account. (check-in: 53f6ec792f user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/vdbemem.c.
118
119
120
121
122
123
124

125
126
127
128
129
130
131
      bPreserve = 0;
    }else{
      sqlite3DbFree(pMem->db, pMem->zMalloc);
      pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
    }
    if( pMem->zMalloc==0 ){
      VdbeMemRelease(pMem);

      pMem->flags = MEM_Null;  
      return SQLITE_NOMEM;
    }
  }

  if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){
    memcpy(pMem->zMalloc, pMem->z, pMem->n);







>







118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
      bPreserve = 0;
    }else{
      sqlite3DbFree(pMem->db, pMem->zMalloc);
      pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
    }
    if( pMem->zMalloc==0 ){
      VdbeMemRelease(pMem);
      pMem->z = 0;
      pMem->flags = MEM_Null;  
      return SQLITE_NOMEM;
    }
  }

  if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){
    memcpy(pMem->zMalloc, pMem->z, pMem->n);