Follow up for Bug 536352 (missing null check and memory leak in nsinstall.c) to fix orange
authorWolfgang Rosenauer <wr@rosenauer.org>
Mon, 18 Jan 2010 12:38:17 +0100
changeset 37275 586eea23fcef7c17b6058e477e953a5282e89f5d
parent 37274 1aa561085c311778ddbd5aa43c0845660bfe22b3
child 37276 196b9d7aef71d7bdbc90cd40992ea42598720604
push idunknown
push userunknown
push dateunknown
bugs536352
milestone1.9.3a1pre
Follow up for Bug 536352 (missing null check and memory leak in nsinstall.c) to fix orange
js/src/config/nsinstall.c
--- a/js/src/config/nsinstall.c
+++ b/js/src/config/nsinstall.c
@@ -253,20 +253,25 @@ copydir( char *from, char *to, mode_t mo
 
   base = xbasename(from);
 
   /* create destination directory */
   destdir = xmalloc((unsigned int)(strlen(to) + 1 + strlen(base) + 1));
   sprintf(destdir, "%s%s%s", to, _DIRECTORY_SEPARATOR, base);
   if (mkdirs(destdir, mode) != 0) {
     fail("cannot make directory %s\n", destdir);
+    free(destdir);
     return;
   }
 
-  dir = opendir(from);
+  if (!(dir = opendir(from))) {
+    fail("cannot open directory %s\n", from);
+    free(destdir);
+    return;
+  }
 
   direntry = xmalloc((unsigned int)PATH_MAX);
   destentry = xmalloc((unsigned int)PATH_MAX);
 
   while ((ep = readdir(dir)))
   {
     if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0)
       continue;
@@ -275,16 +280,17 @@ copydir( char *from, char *to, mode_t mo
     sprintf(destentry, "%s%s%s", destdir, _DIRECTORY_SEPARATOR, ep->d_name);
 
     if (stat(direntry, &sb) == 0 && S_ISDIR(sb.st_mode))
       copydir( direntry, destdir, mode, group, owner, dotimes, uid, gid );
     else
       copyfile( direntry, destentry, mode, group, owner, dotimes, uid, gid );
   }
 
+  free(destdir);
   free(direntry);
   free(destentry);
   closedir(dir);
 }
 
 int
 main(int argc, char **argv)
 {