Fix bugs of database corruption following IO error on systems supporting atomic-write

SQLite on Android uses AUTO_VACUUM option.
When the disk space is critically low and atomic-write option is enabled,
SQLite writes transactions that modify a single database page on disk
without creating a journal file.

Due to a bug, if an IO or disk full error occurs while transferring
the contents to disk, the single page that was modified in the cache
is not being rolled back - cache corruption.
As a result, applications get a database corruption exception
for next database transactions.

This patch changes createFile() to close pReal in case of IO error.
Therefore, cache is being rolled back.

This patch is originated from www.sqlite.org.
(URL: http://www.sqlite.org/src/tktview?name=df678d738a)

Change-Id: Ieecda65d8458cb591bd4d89d8b423a4479f50ea8
diff --git a/dist/sqlite3.c b/dist/sqlite3.c
index 9d01a51..11e6528 100644
--- a/dist/sqlite3.c
+++ b/dist/sqlite3.c
@@ -72614,6 +72614,14 @@
         assert(p->iSize<=p->nBuf);
         rc = sqlite3OsWrite(p->pReal, p->zBuf, p->iSize, 0);
       }
+      if( rc!=SQLITE_OK ){
+        /* If an error occurred while writing to the file, close it before
+        ** returning. This way, SQLite uses the in-memory journal data to
+        ** roll back changes made to the internal page-cache before this
+        ** function was called.  */
+        sqlite3OsClose(pReal);
+        p->pReal = 0;
+      }
     }
   }
   return rc;