Commit 169ad3f6 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Do not manually handle c strings.

parent 4e18daee
......@@ -201,12 +201,10 @@ public:
*/
std::string mrl()
{
char* c_result = libvlc_media_get_mrl(*this);
if ( c_result == NULL )
return std::string();
std::string result = c_result;
libvlc_free(c_result);
return result;
auto str = wrapCStr( libvlc_media_get_mrl(*this) );
if ( str == nullptr )
return {};
return str.get();
}
/**
......@@ -240,12 +238,10 @@ public:
*/
std::string meta(libvlc_meta_t e_meta)
{
char* c_result = libvlc_media_get_meta(*this, e_meta);
if ( c_result == NULL )
return std::string();
std::string result = c_result;
libvlc_free(c_result);
return result;
auto str = wrapCStr(libvlc_media_get_meta(*this, e_meta) );
if ( str == nullptr )
return {};
return str.get();
}
/**
......
......@@ -60,12 +60,10 @@ public:
*/
std::string localizedName()
{
char* c_result = libvlc_media_discoverer_localized_name(*this);
if ( c_result == NULL )
return std::string();
std::string result = c_result;
libvlc_free(c_result);
return result;
auto str = wrapCStr( libvlc_media_discoverer_localized_name(*this) );
if ( str == nullptr )
return {};
return str.get();
}
/**
......
......@@ -1147,12 +1147,10 @@ public:
*/
std::string aspectRatio()
{
char* c_result = libvlc_video_get_aspect_ratio(*this);
if ( c_result == NULL )
return std::string();
std::string result = c_result;
libvlc_free(c_result);
return result;
auto str = wrapCStr( libvlc_video_get_aspect_ratio(*this) );
if ( str == nullptr )
return {};
return str.get();
}
/**
......@@ -1289,12 +1287,10 @@ public:
*/
std::string cropGeometry()
{
char* c_result = libvlc_video_get_crop_geometry(*this);
if ( c_result == NULL )
return std::string();
std::string result = c_result;
libvlc_free(c_result);
return result;
auto str = wrapCStr( libvlc_video_get_crop_geometry(*this) );
if ( str == nullptr )
return {};
return str.get();
}
/**
......@@ -1424,12 +1420,10 @@ public:
*/
std::string marqueeString(unsigned option)
{
char* c_result = libvlc_video_get_marquee_string(*this, option);
if ( c_result == NULL )
return std::string();
std::string result = c_result;
libvlc_free(c_result);
return result;
auto str = wrapCStr( libvlc_video_get_marquee_string(*this, option) );
if ( str == nullptr )
return {};
return str.get();
}
/**
......
......@@ -48,6 +48,11 @@ namespace VLC
{
return ref.get();
}
std::unique_ptr<char, void (*)(void*)> wrapCStr(char* str)
{
return std::unique_ptr<char, void(*)(void*)>( str, [](void* ptr) { libvlc_free(ptr); } );
}
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment