Skip to content

Commit 3b780ac

Browse files
committed
opal/mca: Fix mca_base_verbose file suffix processing
* `-mca mca_base_verbose file:foo` should create an output file with the suffix `foo`. But since we free the pointer at the end of this function then by the time we use it it is pointing to invalid memory. * This commit fixes that corruption * This commit also fixes the behavior of `file:` with no suffix. Makes it the same as `file` without the colon. Signed-off-by: Joshua Hursey <[email protected]>
1 parent 022c658 commit 3b780ac

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

opal/mca/base/mca_base_open.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,12 @@ static void parse_verbose(char *e, opal_output_stream_t *lds)
230230
have_output = true;
231231
}
232232

233-
else if (strcasecmp(ptr, "file") == 0) {
233+
else if (strcasecmp(ptr, "file") == 0 || strcasecmp(ptr, "file:") == 0) {
234234
lds->lds_want_file = true;
235235
have_output = true;
236236
} else if (strncasecmp(ptr, "file:", 5) == 0) {
237237
lds->lds_want_file = true;
238-
lds->lds_file_suffix = ptr + 5;
238+
lds->lds_file_suffix = strdup(ptr + 5);
239239
have_output = true;
240240
} else if (strcasecmp(ptr, "fileappend") == 0) {
241241
lds->lds_want_file = true;

opal/util/output.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ typedef struct {
8787
* Private functions
8888
*/
8989
static void construct(opal_object_t *stream);
90+
static void destruct(opal_object_t *stream);
9091
static int do_open(int output_id, opal_output_stream_t * lds);
9192
static int open_file(int i);
9293
static void free_descriptor(int output_id);
@@ -120,7 +121,7 @@ static bool syslog_opened = false;
120121
#endif
121122
static char *redirect_syslog_ident = NULL;
122123

123-
OBJ_CLASS_INSTANCE(opal_output_stream_t, opal_object_t, construct, NULL);
124+
OBJ_CLASS_INSTANCE(opal_output_stream_t, opal_object_t, construct, destruct);
124125

125126
/*
126127
* Setup the output stream infrastructure
@@ -536,6 +537,15 @@ static void construct(opal_object_t *obj)
536537
stream->lds_want_file_append = false;
537538
stream->lds_file_suffix = NULL;
538539
}
540+
static void destruct(opal_object_t *obj)
541+
{
542+
opal_output_stream_t *stream = (opal_output_stream_t*) obj;
543+
544+
if( NULL != stream->lds_file_suffix ) {
545+
free(stream->lds_file_suffix);
546+
stream->lds_file_suffix = NULL;
547+
}
548+
}
539549

540550
/*
541551
* Back-end of open() and reopen(). Necessary to have it as a

0 commit comments

Comments
 (0)