diff --git a/.gitattributes b/.gitattributes
index 5fe7a63fa3ef85cd155de4e06afe9ca5b60f2ae9..7d92f7bcc6260c0cfd40d778a837cad7feffbb7d 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -833,7 +833,6 @@ testfont binary
 /src/post_modules/SDL/constants.h foreign_ident
 /src/post_modules/SQLite/Makefile.in foreign_ident
 /src/post_modules/SQLite/configure.in foreign_ident
-/src/post_modules/SQLite/sqlite.cmod foreign_ident
 /src/post_modules/Shuffler/Makefile.in foreign_ident
 /src/post_modules/Shuffler/Shuffler.cmod foreign_ident
 /src/post_modules/Shuffler/a_source_pikestring.c foreign_ident
diff --git a/src/post_modules/SQLite/sqlite.cmod b/src/post_modules/SQLite/sqlite.cmod
index fcdb455eb89af49d000693a3ae1df5db248f98eb..3698f884e1b3f55adc4096a20f8926d80f468fff 100644
--- a/src/post_modules/SQLite/sqlite.cmod
+++ b/src/post_modules/SQLite/sqlite.cmod
@@ -1,6 +1,6 @@
 /* sqlite.cmod -*- c -*-
  *
- * $Id: sqlite.cmod,v 1.23 2008/08/01 03:02:36 bill Exp $
+ * $Id$
  */
 
 #include "global.h"
@@ -163,6 +163,16 @@ PIKECLASS ResObj
 
   PIKEFUN array(mapping(string:mixed)) fetch_fields() {
     int i,t;
+    if (!sqlite3_column_name(THIS->stmt, 0)) {
+      /* Documented to happen on malloc() failure,
+       * but can apparently happen in other cases too.
+       * The common case seems to be when called after
+       * the last row has been fetched.
+       * Cf #10035.
+       */
+      push_int(0);
+      return;
+    }
     for(i=0; i<THIS->columns; i++) {
       push_constant_text("name");
       push_text(sqlite3_column_name(THIS->stmt, i));