1 /* 2 ** 2008 Jan 22 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 file contains code to support the concept of "benign" 14 ** malloc failures. 15 ** 16 ** $Id: fault.c,v 1.8 2008/06/20 11:05:38 danielk1977 Exp $ 17 */ 18 19 #include "sqliteInt.h" 20 21 #ifndef SQLITE_OMIT_BUILTIN_TEST 22 23 /* 24 ** If zero, malloc() failures are non-benign. If non-zero, benign. 25 */ 26 static int memfault_is_benign = 0; 27 28 /* 29 ** Return true if a malloc failures are currently considered to be 30 ** benign. A benign fault does not affect the operation of sqlite. 31 ** By constrast a non-benign fault causes sqlite to fail the current 32 ** operation and return SQLITE_NOMEM to the user. 33 */ 34 int sqlite3FaultIsBenign(void){ 35 return memfault_is_benign; 36 } 37 38 /* 39 ** After this routine causes subsequent malloc faults to be either 40 ** benign or hard (not benign), according to the "enable" parameter. 41 ** 42 ** Most faults are hard. In other words, most faults cause 43 ** an error to be propagated back up to the application interface. 44 ** However, sometimes a fault is easily recoverable. For example, 45 ** if a malloc fails while resizing a hash table, this is completely 46 ** recoverable simply by not carrying out the resize. The hash table 47 ** will continue to function normally. So a malloc failure during 48 ** a hash table resize is a benign fault. 49 */ 50 void sqlite3FaultBeginBenign(int id){ 51 memfault_is_benign++; 52 } 53 void sqlite3FaultEndBenign(int id){ 54 memfault_is_benign--; 55 } 56 57 #endif /* #ifndef SQLITE_OMIT_BUILTIN_TEST */ 58 59