/mandos/release

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/release

« back to all changes in this revision

Viewing changes to plugin-runner.c

  • Committer: Teddy Hogeborn
  • Date: 2014-06-14 23:43:07 UTC
  • mto: (237.7.272 trunk)
  • mto: This revision was merged to the branch mainline in revision 317.
  • Revision ID: teddy@recompile.se-20140614234307-i0mh9r2n4orkqtki
plugin-runner: Release memory and close FD's correctly in all cases.

* plugins.d/mandos-client.c (main): Init "direntries" to NULL.  Close
                                    "dir_fd" at fallback label.  Do
                                    not free "direntries" if
                                    scandirat() or scandir() failed.
                                    Do free(direntries) at fallback
                                    label.

Show diffs side-by-side

added added

removed removed

Lines of Context:
349
349
  char *plugindir = NULL;
350
350
  char *argfile = NULL;
351
351
  FILE *conffp;
352
 
  struct dirent **direntries;
 
352
  struct dirent **direntries = NULL;
353
353
  struct stat st;
354
354
  fd_set rfds_all;
355
355
  int ret, maxfd = 0;
829
829
    ret = set_cloexec_flag(dir_fd);
830
830
    if(ret < 0){
831
831
      error(0, errno, "set_cloexec_flag");
832
 
      TEMP_FAILURE_RETRY(close(dir_fd));
833
832
      exitstatus = EX_OSERR;
834
833
      goto fallback;
835
834
    }
875
874
#endif  /* not __GLIBC__ */
876
875
  if(numplugins == -1){
877
876
    error(0, errno, "Could not scan plugin dir");
878
 
    TEMP_FAILURE_RETRY(close(dir_fd));
 
877
    direntries = NULL;
879
878
    exitstatus = EX_OSERR;
880
879
    goto fallback;
881
880
  }
1092
1091
    }
1093
1092
  }
1094
1093
  
 
1094
  free(direntries);
 
1095
  direntries = NULL;
1095
1096
  TEMP_FAILURE_RETRY(close(dir_fd));
 
1097
  dir_fd = -1;
1096
1098
  free_plugin(getplugin(NULL));
1097
1099
  
1098
1100
  for(plugin *p = plugin_list; p != NULL; p = p->next){
1292
1294
    free(custom_argv);
1293
1295
  }
1294
1296
  
 
1297
  free(direntries);
 
1298
  
1295
1299
  if(dir_fd != -1){
1296
1300
    TEMP_FAILURE_RETRY(close(dir_fd));
1297
1301
  }