[vlc-commits] vlc_strfinput: fix race on input_item_t.p_stats

Rémi Denis-Courmont git at videolan.org
Mon Dec 11 21:02:24 CET 2017


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Dec 11 21:10:38 2017 +0200| [895d480b516f01482df7176ccee811c38d665230] | committer: Rémi Denis-Courmont

vlc_strfinput: fix race on input_item_t.p_stats

p_stats is written with the input item lock (by the input thread).
Thus the input item lock is necessary to read and dereference p_stats.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=895d480b516f01482df7176ccee811c38d665230
---

 src/text/strings.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/text/strings.c b/src/text/strings.c
index eae4461006..4b282bb397 100644
--- a/src/text/strings.c
+++ b/src/text/strings.c
@@ -589,12 +589,19 @@ char *vlc_strfinput(input_thread_t *input, const char *s)
                 write_meta(stream, item, vlc_meta_EncodedBy);
                 break;
             case 'f':
-                if (item != NULL && item->p_stats != NULL)
+                if (item != NULL)
                 {
-                    vlc_mutex_lock(&item->p_stats->lock);
-                    vlc_memstream_printf(stream, "%"PRIi64,
+                    vlc_mutex_lock(&item->lock);
+                    if (item->p_stats != NULL)
+                    {
+                        vlc_mutex_lock(&item->p_stats->lock);
+                        vlc_memstream_printf(stream, "%"PRIi64,
                             item->p_stats->i_displayed_pictures);
-                    vlc_mutex_unlock(&item->p_stats->lock);
+                        vlc_mutex_unlock(&item->p_stats->lock);
+                    }
+                    else if (!b_empty_if_na)
+                        vlc_memstream_putc(stream, '-');
+                    vlc_mutex_unlock(&item->lock);
                 }
                 else if (!b_empty_if_na)
                     vlc_memstream_putc(stream, '-');



More information about the vlc-commits mailing list