mirror of
https://github.com/QingdaoU/Judger.git
synced 2025-01-16 01:13:25 +00:00
修复coverity扫描发现的问题
This commit is contained in:
parent
b4c1fc1885
commit
5a89bc363f
@ -37,6 +37,7 @@ void close_file(FILE *fp, ...) {
|
||||
|
||||
int child_process(void *args) {
|
||||
FILE *log_fp = ((child_args *) args)->log_fp;
|
||||
FILE *input_file = NULL, *output_file = NULL, *error_file = NULL;
|
||||
struct config *_config = ((child_args *) args)->_config;
|
||||
|
||||
// set memory limit
|
||||
@ -75,7 +76,6 @@ int child_process(void *args) {
|
||||
}
|
||||
}
|
||||
|
||||
FILE *input_file = NULL, *output_file = NULL, *error_file = NULL;
|
||||
if (_config->input_path != NULL) {
|
||||
input_file = fopen(_config->input_path, "r");
|
||||
if (input_file == NULL) {
|
||||
@ -86,7 +86,6 @@ int child_process(void *args) {
|
||||
// On error, -1 is returned, and errno is set appropriately.
|
||||
if (dup2(fileno(input_file), fileno(stdin)) == -1) {
|
||||
// todo log
|
||||
close_file(input_file);
|
||||
CHILD_ERROR_EXIT(DUP2_FAILED);
|
||||
}
|
||||
}
|
||||
@ -94,33 +93,29 @@ int child_process(void *args) {
|
||||
if (_config->output_path != NULL) {
|
||||
output_file = fopen(_config->output_path, "w");
|
||||
if (output_file == NULL) {
|
||||
close_file(input_file);
|
||||
CHILD_ERROR_EXIT(DUP2_FAILED);
|
||||
}
|
||||
// redirect stdout -> file
|
||||
if (dup2(fileno(output_file), fileno(stdout)) == -1) {
|
||||
close_file(input_file, output_file);
|
||||
CHILD_ERROR_EXIT(DUP2_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
if (_config->error_path != NULL) {
|
||||
// if outfile and error_file is the same path, we use the same file pointer
|
||||
if (strcmp(_config->output_path, _config->error_path) == 0) {
|
||||
if (_config->output_path != NULL && strcmp(_config->output_path, _config->error_path) == 0) {
|
||||
error_file = output_file;
|
||||
}
|
||||
else {
|
||||
error_file = fopen(_config->error_path, "w");
|
||||
if (error_file == NULL) {
|
||||
// todo log
|
||||
close_file(input_file, output_file);
|
||||
CHILD_ERROR_EXIT(DUP2_FAILED);
|
||||
}
|
||||
}
|
||||
// redirect stderr -> file
|
||||
if (dup2(fileno(error_file), fileno(stderr)) == -1) {
|
||||
// todo log
|
||||
close_file(input_file, output_file, error_file);
|
||||
CHILD_ERROR_EXIT(DUP2_FAILED);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
#define CHILD_ERROR_EXIT(error_code)\
|
||||
{\
|
||||
LOG_ERROR(error_code); \
|
||||
close_file(input_file, output_file, error_file); \
|
||||
raise(SIGUSR1); \
|
||||
return -1; \
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
// (ver >> 16) & 0xff, (ver >> 8) & 0xff, ver & 0xff -> real version
|
||||
#define VERSION 0x020000
|
||||
#define VERSION 0x020001
|
||||
|
||||
#define UNLIMITED -1
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user