Protect against freeing config file list twice.
authorJennifer Richards <jennifer@painless-security.com>
Fri, 6 May 2016 15:49:14 +0000 (11:49 -0400)
committerJennifer Richards <jennifer@painless-security.com>
Fri, 6 May 2016 15:49:14 +0000 (11:49 -0400)
common/tr_config.c

index 1da6dc4..fbd5027 100644 (file)
@@ -1029,10 +1029,11 @@ void tr_free_config_file_list(int n, struct dirent ***cfg_files) {
   int ii;
 
   /* if n < 0, then scandir did not allocate anything because it failed */
-  if(n>=0) {
+  if((n>=0) && (*cfg_files != NULL)) {
     for(ii=0; ii<n; ii++) {
       free((*cfg_files)[ii]);
     }
     free(*cfg_files); /* safe even if n==0 */
+    *cfg_files=NULL; /* this will help prevent accidentally freeing twice */
   }
 }