From 010674b3dd69ceebfaa0ae1ebd92776271d7f055 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 5 Feb 2021 11:04:52 -0500 Subject: [PATCH] Fix use of local mem in return value reported by cppcheck --- src/zm_mpeg.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/zm_mpeg.cpp b/src/zm_mpeg.cpp index 7686496b7..3b298705b 100644 --- a/src/zm_mpeg.cpp +++ b/src/zm_mpeg.cpp @@ -263,22 +263,21 @@ void VideoStream::SetupCodec( int colours, int subpixelorder, int width, int hei void VideoStream::SetParameters( ) { } -const char *VideoStream::MimeType( ) const { +const char *VideoStream::MimeType() const { for ( unsigned int i = 0; i < sizeof (mime_data) / sizeof (*mime_data); i++ ) { - if ( strcmp( format, mime_data[i].format ) == 0 ) { - Debug( 1, "MimeType is \"%s\"", mime_data[i].mime_type ); + if ( strcmp(format, mime_data[i].format) == 0 ) { + Debug(1, "MimeType is \"%s\"", mime_data[i].mime_type); return mime_data[i].mime_type; } } const char *mime_type = of->mime_type; if ( !mime_type ) { - std::string mime = "video/"; - mime = mime.append( format ); - mime_type = mime.c_str( ); - Warning( "Unable to determine mime type for '%s' format, using '%s' as default", format, mime_type ); + std::string mime = std::string("video/") + format; + mime_type = strdup(mime.c_str()); // mem leak + Warning( "Unable to determine mime type for '%s' format, using '%s' as default", format, mime_type); } - Debug(1, "MimeType is \"%s\"", mime_type ); + Debug(1, "MimeType is \"%s\"", mime_type); return mime_type; }