Bug 523915 - updater crashes when trying to update with crash reporter open. r=ted.mielczarek
authorRobert Strong <robert.bugzilla@gmail.com>
Fri, 13 Nov 2009 13:11:32 -0800
changeset 34839 b89fd003bdd92e7b81924b4d9f0ea6d11ce519e6
parent 34838 9327ef16ef5945ecb7d1330ffa1ef3216fd01b89
child 34840 f2a2bb94bf9a35b1ca4e6e6e4b4142e78e092879
push idunknown
push userunknown
push dateunknown
reviewersted.mielczarek
bugs523915
milestone1.9.3a1pre
Bug 523915 - updater crashes when trying to update with crash reporter open. r=ted.mielczarek
toolkit/mozapps/update/src/updater/updater.cpp
--- a/toolkit/mozapps/update/src/updater/updater.cpp
+++ b/toolkit/mozapps/update/src/updater/updater.cpp
@@ -497,22 +497,26 @@ static int ensure_remove(const NS_tchar 
   return rv;
 }
 
 static FILE* ensure_open(const NS_tchar *path, const NS_tchar* flags, unsigned int options)
 {
   ensure_write_permissions(path);
   FILE* f = NS_tfopen(path, flags);
   if (NS_tchmod(path, options) != 0) {
-    fclose(f);
+    if (f != NULL) {
+      fclose(f);
+    }
     return NULL;
   }
   struct stat ss;
   if (NS_tstat(path, &ss) != 0 || ss.st_mode != options) {
-    fclose(f);
+    if (f != NULL) {
+      fclose(f);
+    }
     return NULL;
   }
   return f;
 }
 
 // Ensure that the directory containing this file exists.
 static int ensure_parent_dir(const NS_tchar *path)
 {
@@ -594,22 +598,25 @@ static int backup_create(const NS_tchar 
 // the specified file.
 // XXX should be a file move instead
 static int backup_restore(const NS_tchar *path)
 {
   NS_tchar backup[MAXPATHLEN];
   NS_tsnprintf(backup, sizeof(backup), NS_T("%s" BACKUP_EXT), path);
 
   int rv = copy_file(backup, path);
-  if (rv)
+  if (rv) {
+    ensure_remove(backup);
     return rv;
+  }
 
   rv = ensure_remove(backup);
-  if (rv)
+  if (rv) {
     return WRITE_ERROR;
+  }
 
   return OK;
 }
 
 // Discard the backup copy of the specified file.
 static int backup_discard(const NS_tchar *path)
 {
   NS_tchar backup[MAXPATHLEN];