Skip to content

Commit 3332a7d

Browse files
committed
Fixed memory leak and some -Werror=unused-result warnings
Signed-off-by: Joshua Gerrard <[email protected]>
1 parent ced245d commit 3332a7d

File tree

2 files changed

+60
-18
lines changed

2 files changed

+60
-18
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ Josh Hursey, Indiana University, Oak Ridge National Laboratory, Los Alamos Natio
165165
166166
Joshua Gerrard
167167
168+
168169
Joshua Ladd, Mellanox
169170
170171

ompi/errhandler/errhandler_predefined.c

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -177,43 +177,84 @@ static void backend_fatal_aggregate(char *type,
177177
char *name, int *error_code,
178178
va_list arglist)
179179
{
180-
char *arg, *prefix, *err_msg = "Unknown error";
181-
bool err_msg_need_free = false;
180+
char *arg = NULL, *prefix = NULL, *err_msg = NULL;
181+
const char* const unknown_error_code = "Error code: %d (no associated error message)";
182+
const char* const unknown_error = "Unknown error";
183+
const char* const unknown_prefix = "[?:?]";
184+
185+
// these do not own what they point to; they're
186+
// here to avoid repeating expressions such as
187+
// (NULL == foo) ? unknown_foo : foo
188+
const char* usable_prefix = unknown_prefix;
189+
const char* usable_err_msg = unknown_error;
182190

183191
arg = va_arg(arglist, char*);
184192
va_end(arglist);
185193

186-
asprintf(&prefix, "[%s:%d]", ompi_process_info.nodename,
187-
(int) ompi_process_info.pid);
194+
if (asprintf(&prefix, "[%s:%d]",
195+
ompi_process_info.nodename,
196+
(int) ompi_process_info.pid) == -1) {
197+
prefix = NULL;
198+
// non-fatal, we could still go on to give useful information here...
199+
opal_output(0, "%s", "Could not write node and PID to prefix");
200+
opal_output(0, "Node: %s", ompi_process_info.nodename);
201+
opal_output(0, "PID: %d", (int) ompi_process_info.pid);
202+
}
188203

189204
if (NULL != error_code) {
190205
err_msg = ompi_mpi_errnum_get_string(*error_code);
191206
if (NULL == err_msg) {
192-
err_msg_need_free = true;
193-
asprintf(&err_msg, "Error code: %d (no associated error message)",
194-
*error_code);
207+
if (asprintf(&err_msg, unknown_error_code,
208+
*error_code) == -1) {
209+
err_msg = NULL;
210+
opal_output(0, "%s", "Could not write to err_msg");
211+
opal_output(0, unknown_error_code, *error_code);
212+
}
195213
}
196214
}
197215

216+
usable_prefix = (NULL == prefix) ? unknown_prefix : prefix;
217+
usable_err_msg = (NULL == err_msg) ? unknown_error : err_msg;
218+
198219
if (NULL != name) {
199220
opal_show_help("help-mpi-errors.txt",
200-
"mpi_errors_are_fatal", false,
201-
prefix, (NULL == arg) ? "" : "in",
221+
"mpi_errors_are_fatal",
222+
false,
223+
usable_prefix,
224+
(NULL == arg) ? "" : "in",
202225
(NULL == arg) ? "" : arg,
203-
prefix, OMPI_PROC_MY_NAME->jobid, OMPI_PROC_MY_NAME->vpid,
204-
prefix, type, name, prefix, err_msg, prefix, type, prefix);
226+
usable_prefix,
227+
OMPI_PROC_MY_NAME->jobid,
228+
OMPI_PROC_MY_NAME->vpid,
229+
usable_prefix,
230+
type,
231+
name,
232+
usable_prefix,
233+
usable_err_msg,
234+
usable_prefix,
235+
type,
236+
usable_prefix);
205237
} else {
206238
opal_show_help("help-mpi-errors.txt",
207-
"mpi_errors_are_fatal unknown handle", false,
208-
prefix, (NULL == arg) ? "" : "in",
239+
"mpi_errors_are_fatal unknown handle",
240+
false,
241+
usable_prefix,
242+
(NULL == arg) ? "" : "in",
209243
(NULL == arg) ? "" : arg,
210-
prefix, OMPI_PROC_MY_NAME->jobid, OMPI_PROC_MY_NAME->vpid,
211-
prefix, type, prefix, err_msg, prefix, type, prefix);
244+
usable_prefix,
245+
OMPI_PROC_MY_NAME->jobid,
246+
OMPI_PROC_MY_NAME->vpid,
247+
usable_prefix,
248+
type,
249+
usable_prefix,
250+
usable_err_msg,
251+
usable_prefix,
252+
type,
253+
usable_prefix);
212254
}
213255

214-
if (err_msg_need_free) {
215-
free(err_msg);
216-
}
256+
free(prefix);
257+
free(err_msg);
217258
}
218259

219260
/*

0 commit comments

Comments
 (0)