


--- gnucash-2.2.9.orig/src/backend/file/gnc-backend-file.c
+++ gnucash-2.2.9/src/backend/file/gnc-backend-file.c
@@ -722,12 +722,13 @@
              continue;
 
         name = g_build_filename(be->dirname, dent, (gchar*)NULL);
-        len = strlen(name) - 4;
+        len = strlen(name);
 
         /* Is this file associated with the current data file */
-        if (strncmp(name, be->fullpath, pathlen) == 0) 
+        if ((strncmp(name, be->fullpath, pathlen) == 0) &&
+            (len > pathlen))
         {
-            if ((safe_strcmp(name + len, ".LNK") == 0) &&
+            if ((safe_strcmp(name + len - 4, ".LNK") == 0) &&
                 /* Is a lock file. Skip the active lock file */
                 (safe_strcmp(name, be->linkfile) != 0) &&
                 /* Only delete lock files older than the active one */
