X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=plugins%2Fctf%2Fcommon%2Fmetadata%2Fdecoder.c;h=559820b350e953e9e077d6539a842f4910674f4b;hp=cba4756c07d9ce34ccd85535006be8cd08d19be5;hb=47eba00af0f5633717f8139041e2ec257ec39da1;hpb=c3c69044787d7c84ff3d66c661357ac6bb9e17dd diff --git a/plugins/ctf/common/metadata/decoder.c b/plugins/ctf/common/metadata/decoder.c index cba4756c..559820b3 100644 --- a/plugins/ctf/common/metadata/decoder.c +++ b/plugins/ctf/common/metadata/decoder.c @@ -291,6 +291,13 @@ int ctf_metadata_decoder_packetized_file_stream_to_buf_with_mdec( /* Close stream, which also flushes the buffer */ ret = bt_close_memstream(buf, &size, out_fp); + /* + * See fclose(3). Further access to out_fp after both success + * and error, even through another bt_close_memstream(), results + * in undefined behavior. Nullify out_fp to ensure we don't + * fclose it twice on error. + */ + out_fp = NULL; if (ret < 0) { BT_LOGE("Cannot close memory stream: %s: mdec-addr=%p", strerror(errno), mdec);