goto exit;
}
- if (dump_num != scan_num)
- temp_list = (struct file_info *)realloc(temp_list,
+ if (dump_num != scan_num) {
+ struct file_info *const tmp = (struct file_info *)realloc(temp_list,
dump_num * sizeof(struct file_info));
+ if (!tmp) {
+ free(temp_list);
+ dump_num = -1;
+ goto exit;
+ }
+ temp_list = tmp;
+ }
qsort(temp_list, dump_num, sizeof(struct file_info), mtime_cmp);
}
if (r < 0) {
syslog(LOG_ERR, "crash-pipe: Error while saving core file %s: %m. Removing core.\n", core_path);
- (void)unlink(core_path); // XXX check errors here too
+ if (unlink(core_path) < 0) {
+ // ignore errno because we're already dealing with the one from splice
+ // amp the log level to CRIT because things are starting to look pretty grim
+ syslog(LOG_CRIT, "crash-pipe: Error while removing core file %s: %m.\n", core_path);
+ }
}
close(fd);
usage();
exit(EXIT_SUCCESS);
} else if (c == OPT_SAVE_CORE) {
+ if (opt_save_core) {
+ syslog(LOG_WARNING, "crash-pipe: duplicate --save-core passed\n");
+ free(opt_save_core);
+ }
opt_save_core = strdup(optarg);
if (!opt_save_core) {
syslog(LOG_CRIT, "Out of memory. Exiting.");
argc -= optind;
argv += optind;
- if (opt_save_core)
+ if (opt_save_core) {
ret = save_core(opt_save_core);
+ free(opt_save_core);
+ }
return ret >= 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}