blob: c142a32c65ef8240152628b1b9219b241e7905ee [file] [log] [blame]
drh268e72f2015-04-17 14:30:49 +00001/*
2** 2015-04-17
3**
4** The author disclaims copyright to this source code. In place of
5** a legal notice, here is a blessing:
6**
7** May you do good and not evil.
8** May you find forgiveness for yourself and forgive others.
9** May you share freely, never taking more than you give.
10**
11*************************************************************************
12**
13** This is a utility program designed to aid running the SQLite library
14** against an external fuzzer, such as American Fuzzy Lop (AFL)
15** (http://lcamtuf.coredump.cx/afl/). Basically, this program reads
16** SQL text from standard input and passes it through to SQLite for evaluation,
17** just like the "sqlite3" command-line shell. Differences from the
18** command-line shell:
19**
20** (1) The complex "dot-command" extensions are omitted. This
21** prevents the fuzzer from discovering that it can run things
22** like ".shell rm -rf ~"
23**
24** (2) The database is opened with the SQLITE_OPEN_MEMORY flag so that
25** no disk I/O from the database is permitted. The ATTACH command
26** with a filename still uses an in-memory database.
27**
28** (3) The main in-memory database can be initialized from a template
29** disk database so that the fuzzer starts with a database containing
30** content.
31**
32** (4) The eval() SQL function is added, allowing the fuzzer to do
33** interesting recursive operations.
drhf34e9aa2015-04-20 12:50:13 +000034**
35** 2015-04-20: The input text can be divided into separate SQL chunks using
36** lines of the form:
37**
38** |****<...>****|
39**
40** where the "..." is arbitrary text, except the "|" should really be "/".
41** ("|" is used here to avoid compiler warnings about nested comments.)
42** Each such SQL comment is printed as it is encountered. A separate
43** in-memory SQLite database is created to run each chunk of SQL. This
44** feature allows the "queue" of AFL to be captured into a single big
45** file using a command like this:
46**
47** (for i in id:*; do echo '|****<'$i'>****|'; cat $i; done) >~/all-queue.txt
48**
49** (Once again, change the "|" to "/") Then all elements of the AFL queue
drh4a74d072015-04-20 18:58:38 +000050** can be run in a single go (for regression testing, for example) by typing:
drhf34e9aa2015-04-20 12:50:13 +000051**
52** fuzzershell -f ~/all-queue.txt >out.txt
53**
54** After running each chunk of SQL, the database connection is closed. The
55** program aborts if the close fails or if there is any unfreed memory after
56** the close.
drh268e72f2015-04-17 14:30:49 +000057*/
58#include <stdio.h>
59#include <stdlib.h>
60#include <string.h>
61#include <stdarg.h>
drh4a74d072015-04-20 18:58:38 +000062#include <ctype.h>
drh268e72f2015-04-17 14:30:49 +000063#include "sqlite3.h"
64
65/*
66** All global variables are gathered into the "g" singleton.
67*/
68struct GlobalVars {
69 const char *zArgv0; /* Name of program */
70} g;
71
72
73
74/*
75** Print an error message and abort in such a way to indicate to the
76** fuzzer that this counts as a crash.
77*/
78static void abendError(const char *zFormat, ...){
79 va_list ap;
80 fprintf(stderr, "%s: ", g.zArgv0);
81 va_start(ap, zFormat);
82 vfprintf(stderr, zFormat, ap);
83 va_end(ap);
84 fprintf(stderr, "\n");
85 abort();
86}
87/*
88** Print an error message and quit, but not in a way that would look
89** like a crash.
90*/
91static void fatalError(const char *zFormat, ...){
92 va_list ap;
93 fprintf(stderr, "%s: ", g.zArgv0);
94 va_start(ap, zFormat);
95 vfprintf(stderr, zFormat, ap);
96 va_end(ap);
97 fprintf(stderr, "\n");
98 exit(1);
99}
100
101/*
drh4a74d072015-04-20 18:58:38 +0000102** Evaluate some SQL. Abort if unable.
103*/
104static void sqlexec(sqlite3 *db, const char *zFormat, ...){
105 va_list ap;
106 char *zSql;
107 char *zErrMsg = 0;
108 int rc;
109 va_start(ap, zFormat);
110 zSql = sqlite3_vmprintf(zFormat, ap);
111 va_end(ap);
112 rc = sqlite3_exec(db, zSql, 0, 0, &zErrMsg);
113 if( rc ) abendError("failed sql [%s]: %s", zSql, zErrMsg);
114 sqlite3_free(zSql);
115}
116
117/*
drh268e72f2015-04-17 14:30:49 +0000118** This callback is invoked by sqlite3_log().
119*/
120static void shellLog(void *pNotUsed, int iErrCode, const char *zMsg){
121 printf("LOG: (%d) %s\n", iErrCode, zMsg);
122}
123
124/*
125** This callback is invoked by sqlite3_exec() to return query results.
126*/
127static int execCallback(void *NotUsed, int argc, char **argv, char **colv){
128 int i;
129 static unsigned cnt = 0;
130 printf("ROW #%u:\n", ++cnt);
131 for(i=0; i<argc; i++){
132 printf(" %s=", colv[i]);
133 if( argv[i] ){
134 printf("[%s]\n", argv[i]);
135 }else{
136 printf("NULL\n");
137 }
138 }
139 return 0;
140}
141
142/*
143** This callback is invoked by sqlite3_trace() as each SQL statement
144** starts.
145*/
146static void traceCallback(void *NotUsed, const char *zMsg){
147 printf("TRACE: %s\n", zMsg);
148}
149
150/***************************************************************************
151** eval() implementation copied from ../ext/misc/eval.c
152*/
153/*
154** Structure used to accumulate the output
155*/
156struct EvalResult {
157 char *z; /* Accumulated output */
158 const char *zSep; /* Separator */
159 int szSep; /* Size of the separator string */
160 sqlite3_int64 nAlloc; /* Number of bytes allocated for z[] */
161 sqlite3_int64 nUsed; /* Number of bytes of z[] actually used */
162};
163
164/*
165** Callback from sqlite_exec() for the eval() function.
166*/
167static int callback(void *pCtx, int argc, char **argv, char **colnames){
168 struct EvalResult *p = (struct EvalResult*)pCtx;
169 int i;
170 for(i=0; i<argc; i++){
171 const char *z = argv[i] ? argv[i] : "";
172 size_t sz = strlen(z);
173 if( (sqlite3_int64)sz+p->nUsed+p->szSep+1 > p->nAlloc ){
174 char *zNew;
175 p->nAlloc = p->nAlloc*2 + sz + p->szSep + 1;
176 /* Using sqlite3_realloc64() would be better, but it is a recent
177 ** addition and will cause a segfault if loaded by an older version
178 ** of SQLite. */
179 zNew = p->nAlloc<=0x7fffffff ? sqlite3_realloc(p->z, (int)p->nAlloc) : 0;
180 if( zNew==0 ){
181 sqlite3_free(p->z);
182 memset(p, 0, sizeof(*p));
183 return 1;
184 }
185 p->z = zNew;
186 }
187 if( p->nUsed>0 ){
188 memcpy(&p->z[p->nUsed], p->zSep, p->szSep);
189 p->nUsed += p->szSep;
190 }
191 memcpy(&p->z[p->nUsed], z, sz);
192 p->nUsed += sz;
193 }
194 return 0;
195}
196
197/*
198** Implementation of the eval(X) and eval(X,Y) SQL functions.
199**
200** Evaluate the SQL text in X. Return the results, using string
201** Y as the separator. If Y is omitted, use a single space character.
202*/
203static void sqlEvalFunc(
204 sqlite3_context *context,
205 int argc,
206 sqlite3_value **argv
207){
208 const char *zSql;
209 sqlite3 *db;
210 char *zErr = 0;
211 int rc;
212 struct EvalResult x;
213
214 memset(&x, 0, sizeof(x));
215 x.zSep = " ";
216 zSql = (const char*)sqlite3_value_text(argv[0]);
217 if( zSql==0 ) return;
218 if( argc>1 ){
219 x.zSep = (const char*)sqlite3_value_text(argv[1]);
220 if( x.zSep==0 ) return;
221 }
222 x.szSep = (int)strlen(x.zSep);
223 db = sqlite3_context_db_handle(context);
224 rc = sqlite3_exec(db, zSql, callback, &x, &zErr);
225 if( rc!=SQLITE_OK ){
226 sqlite3_result_error(context, zErr, -1);
227 sqlite3_free(zErr);
228 }else if( x.zSep==0 ){
229 sqlite3_result_error_nomem(context);
230 sqlite3_free(x.z);
231 }else{
232 sqlite3_result_text(context, x.z, (int)x.nUsed, sqlite3_free);
233 }
234}
235/* End of the eval() implementation
236******************************************************************************/
237
238/*
239** Print sketchy documentation for this utility program
240*/
241static void showHelp(void){
242 printf("Usage: %s [options]\n", g.zArgv0);
243 printf(
244"Read SQL text from standard input and evaluate it.\n"
245"Options:\n"
drh4a74d072015-04-20 18:58:38 +0000246" --autovacuum Enable AUTOVACUUM mode\n"
drh268e72f2015-04-17 14:30:49 +0000247" -f FILE Read SQL text from FILE instead of standard input\n"
drh4a74d072015-04-20 18:58:38 +0000248" --heap SZ MIN Memory allocator uses SZ bytes & min allocation MIN\n"
drh268e72f2015-04-17 14:30:49 +0000249" --help Show this help text\n"
250" --initdb DBFILE Initialize the in-memory database using template DBFILE\n"
drh4a74d072015-04-20 18:58:38 +0000251" --lookaside N SZ Configure lookaside for N slots of SZ bytes each\n"
252" --pagesize N Set the page size to N\n"
253" --pcache N SZ Configure N pages of pagecache each of size SZ bytes\n"
254" --scratch N SZ Configure scratch memory for N slots of SZ bytes each\n"
255" --utf16be Set text encoding to UTF-16BE\n"
256" --utf16le Set text encoding to UTF-16LE\n"
drh268e72f2015-04-17 14:30:49 +0000257 );
258}
259
drh4a74d072015-04-20 18:58:38 +0000260/*
261** Return the value of a hexadecimal digit. Return -1 if the input
262** is not a hex digit.
263*/
264static int hexDigitValue(char c){
265 if( c>='0' && c<='9' ) return c - '0';
266 if( c>='a' && c<='f' ) return c - 'a' + 10;
267 if( c>='A' && c<='F' ) return c - 'A' + 10;
268 return -1;
269}
270
271/*
272** Interpret zArg as an integer value, possibly with suffixes.
273*/
274static int integerValue(const char *zArg){
275 sqlite3_int64 v = 0;
276 static const struct { char *zSuffix; int iMult; } aMult[] = {
277 { "KiB", 1024 },
278 { "MiB", 1024*1024 },
279 { "GiB", 1024*1024*1024 },
280 { "KB", 1000 },
281 { "MB", 1000000 },
282 { "GB", 1000000000 },
283 { "K", 1000 },
284 { "M", 1000000 },
285 { "G", 1000000000 },
286 };
287 int i;
288 int isNeg = 0;
289 if( zArg[0]=='-' ){
290 isNeg = 1;
291 zArg++;
292 }else if( zArg[0]=='+' ){
293 zArg++;
294 }
295 if( zArg[0]=='0' && zArg[1]=='x' ){
296 int x;
297 zArg += 2;
298 while( (x = hexDigitValue(zArg[0]))>=0 ){
299 v = (v<<4) + x;
300 zArg++;
301 }
302 }else{
303 while( isdigit(zArg[0]) ){
304 v = v*10 + zArg[0] - '0';
305 zArg++;
306 }
307 }
308 for(i=0; i<sizeof(aMult)/sizeof(aMult[0]); i++){
309 if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ){
310 v *= aMult[i].iMult;
311 break;
312 }
313 }
314 if( v>0x7fffffff ) abendError("parameter too large - max 2147483648");
315 return (int)(isNeg? -v : v);
316}
317
drh9985dab2015-04-20 22:36:49 +0000318/*
319** Various operating modes
320*/
321#define FZMODE_Generic 1
322#define FZMODE_Strftime 2
323#define FZMODE_Printf 3
324#define FZMODE_Glob 4
325
drh268e72f2015-04-17 14:30:49 +0000326
327int main(int argc, char **argv){
328 char *zIn = 0; /* Input text */
329 int nAlloc = 0; /* Number of bytes allocated for zIn[] */
330 int nIn = 0; /* Number of bytes of zIn[] used */
331 size_t got; /* Bytes read from input */
332 FILE *in = stdin; /* Where to read SQL text from */
333 int rc = SQLITE_OK; /* Result codes from API functions */
334 int i; /* Loop counter */
drhf34e9aa2015-04-20 12:50:13 +0000335 int iNext; /* Next block of SQL */
drh268e72f2015-04-17 14:30:49 +0000336 sqlite3 *db; /* Open database */
drhf34e9aa2015-04-20 12:50:13 +0000337 sqlite3 *dbInit = 0; /* On-disk database used to initialize the in-memory db */
drh268e72f2015-04-17 14:30:49 +0000338 const char *zInitDb = 0;/* Name of the initialization database file */
339 char *zErrMsg = 0; /* Error message returned from sqlite3_exec() */
drh4a74d072015-04-20 18:58:38 +0000340 const char *zEncoding = 0; /* --utf16be or --utf16le */
341 int nHeap = 0, mnHeap = 0; /* Heap size from --heap */
342 int nLook = 0, szLook = 0; /* --lookaside configuration */
343 int nPCache = 0, szPCache = 0;/* --pcache configuration */
344 int nScratch = 0, szScratch=0;/* --scratch configuration */
345 int pageSize = 0; /* Desired page size. 0 means default */
346 void *pHeap = 0; /* Allocated heap space */
347 void *pLook = 0; /* Allocated lookaside space */
348 void *pPCache = 0; /* Allocated storage for pcache */
349 void *pScratch = 0; /* Allocated storage for scratch */
350 int doAutovac = 0; /* True for --autovacuum */
drh9985dab2015-04-20 22:36:49 +0000351 char *zSql; /* SQL to run */
352 char *zToFree = 0; /* Call sqlite3_free() on this afte running zSql */
353 int iMode = FZMODE_Generic; /* Operating mode */
drh4a74d072015-04-20 18:58:38 +0000354
drh268e72f2015-04-17 14:30:49 +0000355
356 g.zArgv0 = argv[0];
357 for(i=1; i<argc; i++){
358 const char *z = argv[i];
359 if( z[0]=='-' ){
360 z++;
361 if( z[0]=='-' ) z++;
drh4a74d072015-04-20 18:58:38 +0000362 if( strcmp(z,"autovacuum")==0 ){
363 doAutovac = 1;
drh268e72f2015-04-17 14:30:49 +0000364 }else
365 if( strcmp(z, "f")==0 && i+1<argc ){
366 if( in!=stdin ) abendError("only one -f allowed");
367 in = fopen(argv[++i],"rb");
368 if( in==0 ) abendError("cannot open input file \"%s\"", argv[i]);
369 }else
drh4a74d072015-04-20 18:58:38 +0000370 if( strcmp(z,"heap")==0 ){
371 if( i>=argc-2 ) abendError("missing arguments on %s\n", argv[i]);
372 nHeap = integerValue(argv[i+1]);
373 mnHeap = integerValue(argv[i+2]);
374 i += 2;
375 }else
376 if( strcmp(z,"help")==0 ){
377 showHelp();
378 return 0;
379 }else
drh268e72f2015-04-17 14:30:49 +0000380 if( strcmp(z, "initdb")==0 && i+1<argc ){
381 if( zInitDb!=0 ) abendError("only one --initdb allowed");
382 zInitDb = argv[++i];
383 }else
drh4a74d072015-04-20 18:58:38 +0000384 if( strcmp(z,"lookaside")==0 ){
385 if( i>=argc-2 ) abendError("missing arguments on %s", argv[i]);
386 nLook = integerValue(argv[i+1]);
387 szLook = integerValue(argv[i+2]);
388 i += 2;
389 }else
drh9985dab2015-04-20 22:36:49 +0000390 if( strcmp(z,"mode")==0 ){
391 if( i>=argc-1 ) abendError("missing argument on %s", argv[i]);
392 z = argv[++i];
393 if( strcmp(z,"generic")==0 ){
394 iMode = FZMODE_Printf;
395 }else if( strcmp(z, "glob")==0 ){
396 iMode = FZMODE_Glob;
397 }else if( strcmp(z, "printf")==0 ){
398 iMode = FZMODE_Printf;
399 }else if( strcmp(z, "strftime")==0 ){
400 iMode = FZMODE_Strftime;
401 }else{
402 abendError("unknown --mode: %s", z);
403 }
404 }else
drh4a74d072015-04-20 18:58:38 +0000405 if( strcmp(z,"pagesize")==0 ){
406 if( i>=argc-1 ) abendError("missing argument on %s", argv[i]);
407 pageSize = integerValue(argv[++i]);
408 }else
409 if( strcmp(z,"pcache")==0 ){
410 if( i>=argc-2 ) abendError("missing arguments on %s", argv[i]);
411 nPCache = integerValue(argv[i+1]);
412 szPCache = integerValue(argv[i+2]);
413 i += 2;
414 }else
415 if( strcmp(z,"scratch")==0 ){
416 if( i>=argc-2 ) abendError("missing arguments on %s", argv[i]);
417 nScratch = integerValue(argv[i+1]);
418 szScratch = integerValue(argv[i+2]);
419 i += 2;
420 }else
421 if( strcmp(z,"utf16le")==0 ){
422 zEncoding = "utf16le";
423 }else
424 if( strcmp(z,"utf16be")==0 ){
425 zEncoding = "utf16be";
426 }else
drh268e72f2015-04-17 14:30:49 +0000427 {
428 abendError("unknown option: %s", argv[i]);
429 }
430 }else{
431 abendError("unknown argument: %s", argv[i]);
432 }
433 }
434 sqlite3_config(SQLITE_CONFIG_LOG, shellLog, 0);
drh4a74d072015-04-20 18:58:38 +0000435 if( nHeap>0 ){
436 pHeap = malloc( nHeap );
437 if( pHeap==0 ) fatalError("cannot allocate %d-byte heap\n", nHeap);
438 rc = sqlite3_config(SQLITE_CONFIG_HEAP, pHeap, nHeap, mnHeap);
439 if( rc ) abendError("heap configuration failed: %d\n", rc);
440 }
441 if( nLook>0 ){
442 sqlite3_config(SQLITE_CONFIG_LOOKASIDE, 0, 0);
443 if( szLook>0 ){
444 pLook = malloc( nLook*szLook );
445 if( pLook==0 ) fatalError("out of memory");
446 }
447 }
448 if( nScratch>0 && szScratch>0 ){
449 pScratch = malloc( nScratch*(sqlite3_int64)szScratch );
450 if( pScratch==0 ) fatalError("cannot allocate %lld-byte scratch",
451 nScratch*(sqlite3_int64)szScratch);
452 rc = sqlite3_config(SQLITE_CONFIG_SCRATCH, pScratch, szScratch, nScratch);
453 if( rc ) abendError("scratch configuration failed: %d\n", rc);
454 }
455 if( nPCache>0 && szPCache>0 ){
456 pPCache = malloc( nPCache*(sqlite3_int64)szPCache );
457 if( pPCache==0 ) fatalError("cannot allocate %lld-byte pcache",
458 nPCache*(sqlite3_int64)szPCache);
459 rc = sqlite3_config(SQLITE_CONFIG_PAGECACHE, pPCache, szPCache, nPCache);
460 if( rc ) abendError("pcache configuration failed: %d", rc);
461 }
drh268e72f2015-04-17 14:30:49 +0000462 while( !feof(in) ){
drhf34e9aa2015-04-20 12:50:13 +0000463 nAlloc += nAlloc+1000;
464 zIn = realloc(zIn, nAlloc);
drh268e72f2015-04-17 14:30:49 +0000465 if( zIn==0 ) fatalError("out of memory");
466 got = fread(zIn+nIn, 1, nAlloc-nIn-1, in);
467 nIn += (int)got;
468 zIn[nIn] = 0;
469 if( got==0 ) break;
470 }
drhf34e9aa2015-04-20 12:50:13 +0000471 if( zInitDb ){
472 rc = sqlite3_open_v2(zInitDb, &dbInit, SQLITE_OPEN_READONLY, 0);
473 if( rc!=SQLITE_OK ){
474 abendError("unable to open initialization database \"%s\"", zInitDb);
475 }
drh268e72f2015-04-17 14:30:49 +0000476 }
drhf34e9aa2015-04-20 12:50:13 +0000477 for(i=0; i<nIn; i=iNext){
478 char cSaved;
479 if( strncmp(&zIn[i], "/****<",6)==0 ){
480 char *z = strstr(&zIn[i], ">****/");
481 if( z ){
482 z += 6;
483 printf("%.*s\n", (int)(z-&zIn[i]), &zIn[i]);
484 i += (int)(z-&zIn[i]);
485 }
486 }
487 for(iNext=i; iNext<nIn && strncmp(&zIn[iNext],"/****<",6)!=0; iNext++){}
drh3fb2cc12015-04-22 11:16:34 +0000488 cSaved = zIn[iNext];
489 zIn[iNext] = 0;
490 if( iMode!=FZMODE_Generic && sqlite3_strglob("'*',*",&zIn[i])!=0 ){
491 zIn[iNext] = cSaved;
492 continue;
493 }
drhf34e9aa2015-04-20 12:50:13 +0000494 rc = sqlite3_open_v2(
495 "main.db", &db,
496 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_MEMORY,
497 0);
498 if( rc!=SQLITE_OK ){
499 abendError("Unable to open the in-memory database");
500 }
drh4a74d072015-04-20 18:58:38 +0000501 if( pLook ){
502 rc = sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE, pLook, szLook, nLook);
503 if( rc!=SQLITE_OK ) abendError("lookaside configuration filed: %d", rc);
504 }
drhf34e9aa2015-04-20 12:50:13 +0000505 if( zInitDb ){
506 sqlite3_backup *pBackup;
507 pBackup = sqlite3_backup_init(db, "main", dbInit, "main");
508 rc = sqlite3_backup_step(pBackup, -1);
509 if( rc!=SQLITE_DONE ){
510 abendError("attempt to initialize the in-memory database failed (rc=%d)",
511 rc);
512 }
513 sqlite3_backup_finish(pBackup);
514 }
515 sqlite3_trace(db, traceCallback, 0);
516 sqlite3_create_function(db, "eval", 1, SQLITE_UTF8, 0, sqlEvalFunc, 0, 0);
517 sqlite3_create_function(db, "eval", 2, SQLITE_UTF8, 0, sqlEvalFunc, 0, 0);
518 sqlite3_limit(db, SQLITE_LIMIT_LENGTH, 1000000);
drh4a74d072015-04-20 18:58:38 +0000519 if( zEncoding ) sqlexec(db, "PRAGMA encoding=%s", zEncoding);
520 if( pageSize ) sqlexec(db, "PRAGMA pagesize=%d", pageSize);
521 if( doAutovac ) sqlexec(db, "PRAGMA auto_vacuum=FULL");
drhf34e9aa2015-04-20 12:50:13 +0000522 printf("INPUT (offset: %d, size: %d): [%s]\n",
523 i, (int)strlen(&zIn[i]), &zIn[i]);
drh9985dab2015-04-20 22:36:49 +0000524 zSql = &zIn[i];
525 switch( iMode ){
526 case FZMODE_Glob:
527 zSql = zToFree = sqlite3_mprintf("SELECT glob(%s);", zSql);
528 break;
529 case FZMODE_Printf:
530 zSql = zToFree = sqlite3_mprintf("SELECT printf(%s);", zSql);
531 break;
532 case FZMODE_Strftime:
533 zSql = zToFree = sqlite3_mprintf("SELECT strftime(%s);", zSql);
534 break;
535 }
536 rc = sqlite3_exec(db, zSql, execCallback, 0, &zErrMsg);
537 if( zToFree ){
538 sqlite3_free(zToFree);
539 zToFree = 0;
540 }
drhf34e9aa2015-04-20 12:50:13 +0000541 zIn[iNext] = cSaved;
542
543 printf("RESULT-CODE: %d\n", rc);
544 if( zErrMsg ){
545 printf("ERROR-MSG: [%s]\n", zErrMsg);
546 sqlite3_free(zErrMsg);
547 }
548 rc = sqlite3_close(db);
549 if( rc ){
550 abendError("sqlite3_close() failed with rc=%d", rc);
551 }
552 if( sqlite3_memory_used()>0 ){
553 abendError("memory in use after close: %lld bytes", sqlite3_memory_used());
554 }
555 }
556 free(zIn);
drh4a74d072015-04-20 18:58:38 +0000557 free(pHeap);
558 free(pLook);
559 free(pScratch);
560 free(pPCache);
drhf34e9aa2015-04-20 12:50:13 +0000561 return 0;
drh268e72f2015-04-17 14:30:49 +0000562}