[vlc-devel] [PATCH] mkv: replace manual memory management of mkv_track_t::psz_codec
Filip Roséen
filip at atch.se
Thu Sep 1 04:06:17 CEST 2016
The previous implementation caused leakage of the data-member in
question due to missing clean-up. The manual memory management is now
replaced by std::string.
---
modules/demux/mkv/matroska_segment.cpp | 4 ++--
modules/demux/mkv/matroska_segment_parse.cpp | 10 +++++-----
modules/demux/mkv/mkv.hpp | 2 +-
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/modules/demux/mkv/matroska_segment.cpp b/modules/demux/mkv/matroska_segment.cpp
index 49c240a..3e0bb4e 100644
--- a/modules/demux/mkv/matroska_segment.cpp
+++ b/modules/demux/mkv/matroska_segment.cpp
@@ -909,7 +909,7 @@ void matroska_segment_c::ComputeTrackPriority()
tracks_map_t::key_type track_id = it->first;
tracks_map_t::mapped_type& track = it->second;
- if( unlikely( track.fmt.i_cat == UNKNOWN_ES || !track.psz_codec ) )
+ if( unlikely( track.fmt.i_cat == UNKNOWN_ES || track.codec.empty() ) )
{
msg_Warn( &sys.demuxer, "invalid track[%d]", static_cast<int>( track_id ) );
track.p_es = NULL;
@@ -1076,7 +1076,7 @@ bool matroska_segment_c::ESCreate()
tracks_map_t::key_type track_id = it->first;
tracks_map_t::mapped_type& track = it->second;
- if( unlikely( track.fmt.i_cat == UNKNOWN_ES || !track.psz_codec ) )
+ if( unlikely( track.fmt.i_cat == UNKNOWN_ES || track.codec.empty() ) )
{
msg_Warn( &sys.demuxer, "invalid track[%d]", static_cast<int>( track_id ) );
track.p_es = NULL;
diff --git a/modules/demux/mkv/matroska_segment_parse.cpp b/modules/demux/mkv/matroska_segment_parse.cpp
index 7985656..67237f3 100644
--- a/modules/demux/mkv/matroska_segment_parse.cpp
+++ b/modules/demux/mkv/matroska_segment_parse.cpp
@@ -218,7 +218,7 @@ void matroska_segment_c::ParseTrackEntry( KaxTrackEntry *m )
track.i_extra_data = 0;
track.p_extra_data = NULL;
- track.psz_codec = NULL;
+ track.codec = "";
track.b_dts_only = false;
track.b_pts_only = false;
@@ -383,7 +383,7 @@ void matroska_segment_c::ParseTrackEntry( KaxTrackEntry *m )
}
E_CASE( KaxCodecID, codecid )
{
- vars.tk->psz_codec = strdup( std::string( codecid ).c_str() );
+ vars.tk->codec = std::string( codecid );
debug( vars, "Track CodecId=%s", std::string( codecid ).c_str() ) ;
}
E_CASE( KaxCodecPrivate, cpriv )
@@ -1243,7 +1243,7 @@ void matroska_segment_c::ParseCluster( KaxCluster *cluster, bool b_update_start_
int32_t matroska_segment_c::TrackInit( mkv_track_t * p_tk )
{
- if( p_tk->psz_codec == NULL )
+ if( p_tk->codec.empty() )
{
msg_Err( &sys.demuxer, "Empty codec id" );
p_tk->fmt.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
@@ -1817,14 +1817,14 @@ int32_t matroska_segment_c::TrackInit( mkv_track_t * p_tk )
};
try {
- TrackCodecHandlers::Dispatcher().send( p_tk->psz_codec,
+ TrackCodecHandlers::Dispatcher().send( p_tk->codec.c_str(),
TrackCodecHandlers::Payload( captures )
);
}
catch (std::exception const& e)
{
msg_Err( &sys.demuxer, "Error when trying to initiate track (codec: %s): %s",
- p_tk->psz_codec, e.what () );
+ p_tk->codec.c_str(), e.what () );
}
return 0;
diff --git a/modules/demux/mkv/mkv.hpp b/modules/demux/mkv/mkv.hpp
index 6bbca6b..6535814 100644
--- a/modules/demux/mkv/mkv.hpp
+++ b/modules/demux/mkv/mkv.hpp
@@ -193,7 +193,7 @@ class mkv_track_t
unsigned int i_extra_data;
uint8_t *p_extra_data;
- char *psz_codec;
+ std::string codec;
bool b_dts_only;
bool b_pts_only;
--
2.9.3
More information about the vlc-devel
mailing list