Bug 536352 - missing null check and memory leak in nsinstall.c. r=ted
authorAiken Tie <ekrem.tomur@gmail.com>
Mon, 18 Jan 2010 11:22:03 +0100
changeset 37274 1aa561085c311778ddbd5aa43c0845660bfe22b3
parent 37273 dc0226af099994828ac7cb049da30f12dfab397a
child 37275 586eea23fcef7c17b6058e477e953a5282e89f5d
push id11198
push userwr@rosenauer.org
push dateMon, 18 Jan 2010 10:23:37 +0000
treeherdermozilla-central@1aa561085c31 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs536352
milestone1.9.3a1pre
Bug 536352 - missing null check and memory leak in nsinstall.c. r=ted
config/nsinstall.c
--- a/config/nsinstall.c
+++ b/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)
 {