From c7e505dc818df14f6418a67256ae235a92a57a6f Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 5 Oct 2011 22:16:02 +0000 Subject: [PATCH] - client: fix memory leak when reading stderr of completed job. This caused 128KB + size of stderr loss for each job. - client: print error message if reading stderr fails (e.g. because of malloc failure) svn path=/trunk/boinc/; revision=24336 --- checkin_notes | 10 ++++++++++ client/app.h | 2 +- client/app_control.cpp | 21 ++++++++++++++++----- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/checkin_notes b/checkin_notes index 8029be294f..55eb12fb72 100644 --- a/checkin_notes +++ b/checkin_notes @@ -6821,3 +6821,13 @@ Rom 5 Oct 2011 lib/ diagnostics.cpp + +David 5 Oct + - client: fix memory leak when reading stderr of completed job. + This caused 128KB + size of stderr loss for each job. + - client: print error message if reading stderr fails + (e.g. because of malloc failure) + + client/ + app.h + app_control.cpp diff --git a/client/app.h b/client/app.h index 0d36ce5269..be19633b6b 100644 --- a/client/app.h +++ b/client/app.h @@ -244,7 +244,7 @@ struct ACTIVE_TASK { bool get_app_status_msg(); bool get_trickle_up_msg(); double est_dur(); - bool read_stderr_file(); + int read_stderr_file(); bool finish_file_present(); bool temporary_exit_file_present(double&); void init_app_init_data(APP_INIT_DATA&); diff --git a/client/app_control.cpp b/client/app_control.cpp index 9abd521375..15d097a0b6 100644 --- a/client/app_control.cpp +++ b/client/app_control.cpp @@ -490,7 +490,12 @@ void ACTIVE_TASK::handle_exited_app(int stat) { if (!will_restart) { copy_output_files(); - read_stderr_file(); + int retval = read_stderr_file(); + if (retval) { + msg_printf(result->project, MSG_INTERNAL_ERROR, + "read_stderr_file(): %s", boincerror(retval) + ); + } client_clean_out_dir(slot_dir, "handle_exited_app()"); clear_schedule_backoffs(this); // clear scheduling backoffs of jobs waiting for GPU @@ -772,7 +777,7 @@ int ACTIVE_TASK::abort_task(int exit_status, const char* msg) { // check for the stderr file, copy to result record // -bool ACTIVE_TASK::read_stderr_file() { +int ACTIVE_TASK::read_stderr_file() { char* buf1, *buf2; char path[256]; @@ -781,16 +786,22 @@ bool ACTIVE_TASK::read_stderr_file() { // int max_len = 63*1024; sprintf(path, "%s/%s", slot_dir, STDERR_FILE); - if (!boinc_file_exists(path)) return false; + if (!boinc_file_exists(path)) return 0; if (read_file_malloc(path, buf1, max_len, !config.stderr_head)) { - return false; + return ERR_MALLOC; } buf2 = (char*)malloc(2*max_len); + if (!buf2) { + free(buf1); + return ERR_MALLOC; + } non_ascii_escape(buf1, buf2, 2*max_len); result->stderr_out += "\n"; result->stderr_out += buf2; result->stderr_out += "\n\n"; - return true; + free(buf1); + free(buf2); + return 0; } // tell a running app to reread project preferences.