Skip to content

Commit 7dab180

Browse files
authored
Merge pull request #2639 from jsquyres/pr/v2.x/warnings-and-minor-mem-leak
v2.x: Fixed memory leak and some -Werror=unused-result warnings
2 parents c201d8b + 9822012 commit 7dab180

File tree

2 files changed

+62
-18
lines changed

2 files changed

+62
-18
lines changed

AUTHORS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ Jose Roman, Universitat Politecnica de Valencia
144144
Josh Hursey, Indiana University, Oak Ridge National Laboratory, Los Alamos National Laboratory, Lawrence Berkeley National Laboratory, University of Wisconsin-La Crosse, IBM
145145
146146
147+
Joshua Gerrard
148+
149+
147150
Joshua Ladd, Mellanox
148151
149152

ompi/errhandler/errhandler_predefined.c

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -177,45 +177,86 @@ 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
assert(ompi_mpi_initialized && !ompi_mpi_finalized);
184192

185193
arg = va_arg(arglist, char*);
186194
va_end(arglist);
187195

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

191206
if (NULL != error_code) {
192207
err_msg = ompi_mpi_errnum_get_string(*error_code);
193208
if (NULL == err_msg) {
194-
err_msg_need_free = true;
195-
asprintf(&err_msg, "Error code: %d (no associated error message)",
196-
*error_code);
209+
if (asprintf(&err_msg, unknown_error_code,
210+
*error_code) == -1) {
211+
err_msg = NULL;
212+
opal_output(0, "%s", "Could not write to err_msg");
213+
opal_output(0, unknown_error_code, *error_code);
214+
}
197215
}
198216
}
199217

218+
usable_prefix = (NULL == prefix) ? unknown_prefix : prefix;
219+
usable_err_msg = (NULL == err_msg) ? unknown_error : err_msg;
220+
200221
if (NULL != name) {
201222
opal_show_help("help-mpi-errors.txt",
202-
"mpi_errors_are_fatal", false,
203-
prefix, (NULL == arg) ? "" : "in",
223+
"mpi_errors_are_fatal",
224+
false,
225+
usable_prefix,
226+
(NULL == arg) ? "" : "in",
204227
(NULL == arg) ? "" : arg,
205-
prefix, OMPI_PROC_MY_NAME->jobid, OMPI_PROC_MY_NAME->vpid,
206-
prefix, type, name, prefix, err_msg, prefix, type, prefix);
228+
usable_prefix,
229+
OMPI_PROC_MY_NAME->jobid,
230+
OMPI_PROC_MY_NAME->vpid,
231+
usable_prefix,
232+
type,
233+
name,
234+
usable_prefix,
235+
usable_err_msg,
236+
usable_prefix,
237+
type,
238+
usable_prefix);
207239
} else {
208240
opal_show_help("help-mpi-errors.txt",
209-
"mpi_errors_are_fatal unknown handle", false,
210-
prefix, (NULL == arg) ? "" : "in",
241+
"mpi_errors_are_fatal unknown handle",
242+
false,
243+
usable_prefix,
244+
(NULL == arg) ? "" : "in",
211245
(NULL == arg) ? "" : arg,
212-
prefix, OMPI_PROC_MY_NAME->jobid, OMPI_PROC_MY_NAME->vpid,
213-
prefix, type, prefix, err_msg, prefix, type, prefix);
246+
usable_prefix,
247+
OMPI_PROC_MY_NAME->jobid,
248+
OMPI_PROC_MY_NAME->vpid,
249+
usable_prefix,
250+
type,
251+
usable_prefix,
252+
usable_err_msg,
253+
usable_prefix,
254+
type,
255+
usable_prefix);
214256
}
215257

216-
if (err_msg_need_free) {
217-
free(err_msg);
218-
}
258+
free(prefix);
259+
free(err_msg);
219260
}
220261

221262
/*

0 commit comments

Comments
 (0)