[vlc-devel] [PATCH 10/10] libvlc: keep the MRL strings in the libvlc_media_t
Steve Lhomme
robux4 at ycbcr.xyz
Mon May 27 15:38:22 CEST 2019
It will be free'd with the media.
Incidentally the slave psz_uri which was set with these values, doesn't need to
be free'd anymore.
---
include/vlc/libvlc_media.h | 4 ++--
lib/media.c | 9 +++++++--
lib/media_internal.h | 1 +
test/libvlc/media.c | 3 +--
test/libvlc/media_discoverer.c | 1 -
test/libvlc/slaves.c | 14 ++++----------
6 files changed, 15 insertions(+), 17 deletions(-)
diff --git a/include/vlc/libvlc_media.h b/include/vlc/libvlc_media.h
index 26b5e52b41..7debb51db7 100644
--- a/include/vlc/libvlc_media.h
+++ b/include/vlc/libvlc_media.h
@@ -311,7 +311,7 @@ typedef enum libvlc_media_slave_type_t
*/
typedef struct libvlc_media_slave_t
{
- char * psz_uri;
+ const char * psz_uri;
libvlc_media_slave_type_t i_type;
unsigned int i_priority;
} libvlc_media_slave_t;
@@ -551,7 +551,7 @@ LIBVLC_API void libvlc_media_release( libvlc_media_t *p_md );
* \param p_md a media descriptor object
* \return string with mrl of media descriptor object
*/
-LIBVLC_API char *libvlc_media_get_mrl( libvlc_media_t *p_md );
+LIBVLC_API const char *libvlc_media_get_mrl( libvlc_media_t *p_md );
/**
* Duplicate a media descriptor object.
diff --git a/lib/media.c b/lib/media.c
index c5fe11aebc..b10bacd54d 100644
--- a/lib/media.c
+++ b/lib/media.c
@@ -580,6 +580,9 @@ void libvlc_media_release( libvlc_media_t *p_md )
for (size_t i=0; i<ARRAY_SIZE(p_md->metas); i++)
free( p_md->metas[i] );
+
+ free( p_md->psz_mrl );
+
free( p_md );
}
@@ -605,11 +608,13 @@ libvlc_media_duplicate( libvlc_media_t *p_md_orig )
/**************************************************************************
* Get mrl from a media descriptor object
**************************************************************************/
-char *
+const char *
libvlc_media_get_mrl( libvlc_media_t * p_md )
{
assert( p_md );
- return input_item_GetURI( p_md->p_input_item );
+ free( p_md->psz_mrl );
+ p_md->psz_mrl = input_item_GetURI( p_md->p_input_item );
+ return p_md->psz_mrl;
}
/**************************************************************************
diff --git a/lib/media_internal.h b/lib/media_internal.h
index eed5d5708d..71f7ac38c4 100644
--- a/lib/media_internal.h
+++ b/lib/media_internal.h
@@ -49,6 +49,7 @@ struct libvlc_media_t
bool has_asked_preparse;
/* strings read by the host and released with the media */
+ char *psz_mrl;
char *metas[ libvlc_meta_Last+1 ];
};
diff --git a/test/libvlc/media.c b/test/libvlc/media.c
index 60a4435fcf..28911ac762 100644
--- a/test/libvlc/media.c
+++ b/test/libvlc/media.c
@@ -209,7 +209,7 @@ static void subitem_added(const libvlc_event_t *event, void *user_data)
libvlc_media_t *m = event->u.media_subitem_added.new_child;
assert (m);
- char *mrl = libvlc_media_get_mrl (m);
+ const char *mrl = libvlc_media_get_mrl (m);
assert (mrl);
const char *file = strrchr (mrl, FILE_SEPARATOR);
@@ -226,7 +226,6 @@ static void subitem_added(const libvlc_event_t *event, void *user_data)
subitems_found[i] = true;
}
}
- free (mrl);
#undef FILE_SEPARATOR
}
diff --git a/test/libvlc/media_discoverer.c b/test/libvlc/media_discoverer.c
index dde3b94a16..83705f0fc2 100644
--- a/test/libvlc/media_discoverer.c
+++ b/test/libvlc/media_discoverer.c
@@ -30,7 +30,6 @@ ml_item_event(const struct libvlc_event_t *p_ev, const char *psz_event)
test_log("item %s(%d): '%s'\n", psz_event,
p_ev->u.media_list_item_added.index, psz_mrl);
- free(psz_mrl);
}
static void
diff --git a/test/libvlc/slaves.c b/test/libvlc/slaves.c
index 7b2c24fa43..6837c4965e 100644
--- a/test/libvlc/slaves.c
+++ b/test/libvlc/slaves.c
@@ -52,11 +52,11 @@ media_parse_sync(libvlc_media_t *p_m)
vlc_sem_destroy (&sem);
}
-static char *
+static const char *
path_to_mrl(libvlc_instance_t *p_vlc, const char *psz_path)
{
libvlc_media_t *p_m = libvlc_media_new_path(p_vlc, psz_path);
- char *psz_mrl = libvlc_media_get_mrl(p_m);
+ const char *psz_mrl = libvlc_media_get_mrl(p_m);
libvlc_media_release(p_m);
return psz_mrl;
}
@@ -115,7 +115,7 @@ test_media_has_slaves_from_parent(libvlc_instance_t *p_vlc,
printf("Parse media dir to get subitems\n");
media_parse_sync(p_m);
- char *psz_main_media_mrl = path_to_mrl(p_vlc, psz_main_media);
+ const char *psz_main_media_mrl = path_to_mrl(p_vlc, psz_main_media);
assert(psz_main_media_mrl != NULL);
printf("Main media mrl: '%s'\n", psz_main_media_mrl);
@@ -130,19 +130,16 @@ test_media_has_slaves_from_parent(libvlc_instance_t *p_vlc,
{
p_subm = libvlc_media_list_item_at_index(p_ml, i);
assert(p_subm != NULL);
- char *psz_mrl = libvlc_media_get_mrl(p_subm);
+ const char *psz_mrl = libvlc_media_get_mrl(p_subm);
assert(psz_mrl != NULL);
if (strcmp(psz_main_media_mrl, psz_mrl) == 0)
{
printf("Found main media\n");
- free(psz_mrl);
break;
}
- free(psz_mrl);
libvlc_media_release(p_subm);
p_subm = NULL;
}
- free(psz_main_media_mrl);
libvlc_media_list_unlock(p_ml);
libvlc_media_list_release(p_ml);
@@ -235,8 +232,5 @@ main (void)
test_media_has_slaves_from_parent(p_vlc, SLAVES_DIR "/test.mp4", NULL, 0);
libvlc_release(p_vlc);
- for (unsigned int i = 0; i < EXPECTED_SLAVES_COUNT; ++i)
- free(p_expected_slaves[i].psz_uri);
-
return 0;
}
--
2.17.1
More information about the vlc-devel
mailing list