[vlc-commits] [Git][videolan/vlc][master] 2 commits: player: osd: early exit on track == NULL

Hugo Beauzée-Luyssen (@chouquette) gitlab at videolan.org
Sat Mar 26 11:56:26 UTC 2022



Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC


Commits:
dbec47c8 by Alexandre Janniaux at 2022-03-26T11:36:39+00:00
player: osd: early exit on track == NULL

Avoid the indentation level on the whole function, allowing to easily
document the early return case as a special edge case and clarifying the
rest of the block.

- - - - -
da50ca64 by Alexandre Janniaux at 2022-03-26T11:36:39+00:00
player: osd: fix memory leak on vlc_memstream

Fix memstream stream being open but never closed when zero tracks were
to be displayed to the OSD. The code was opening the vlc_memstream from
the start but was freeing the pointer only when the close of the
memstream succeeded AND the number of tracks was non-null.

Instead, this patch reorder the code so that the vlc_memstream is
allocated only when there is at least one track to display and early
exit with the N/A OSD message otherwise.

Then it tries to close the memstream and exit in case of error.

Finally, the text is sent to the OSD and the pointer is freed.

It was raising an ASAN leak report on test_src_player through the
test_teletext test function.

Fixes #26732

- - - - -


1 changed file:

- src/player/osd.c


Changes:

=====================================
src/player/osd.c
=====================================
@@ -210,7 +210,6 @@ vlc_player_osd_Tracks(vlc_player_t *player, vlc_es_id_t * const *selected, vlc_e
     const char *cat_name = es_format_category_to_string(cat);
     int tracks_count = 0;
     struct vlc_memstream stream;
-    vlc_memstream_open(&stream);
 
     for (size_t i = 0; selected[i] != NULL; i++)
     {
@@ -220,25 +219,42 @@ vlc_player_osd_Tracks(vlc_player_t *player, vlc_es_id_t * const *selected, vlc_e
 
         const struct vlc_player_track *track =
             vlc_player_GetTrack(player, selected[i]);
-        if (track)
+        /* The track can be NULL if it was terminated by the playback.
+         * In this case, we have nothing to display for it. */
+        if (unlikely(track == NULL))
+            continue;
+
+        /* Open the stream for the first track, and exit in case of error.
+         * On the next tracks, add comma to separate the track names. */
+        if (tracks_count == 0)
         {
-            if (tracks_count != 0)
-                vlc_memstream_puts(&stream, ", ");
-            vlc_memstream_puts(&stream, track->name);
-            tracks_count++;
+            if (vlc_memstream_open(&stream) != 0)
+                return;
         }
+        else
+            vlc_memstream_puts(&stream, ", ");
+
+        vlc_memstream_puts(&stream, track->name);
+        tracks_count++;
     }
-    if (vlc_memstream_close(&stream) == 0 && tracks_count != 0)
+
+    if (tracks_count == 0)
     {
-        if (tracks_count == 1)
-            vlc_player_osd_Message(player, _("%s track: %s"), cat_name,
-                                   stream.ptr);
-        else
-            vlc_player_osd_Message(player, _("%s tracks: %s"), cat_name,
-                                   stream.ptr);
-        free(stream.ptr);
-    } else if (tracks_count == 0)
         vlc_player_osd_Message(player, _("%s track: %s"), cat_name, _("N/A"));
+        return;
+    }
+
+    /* The vlc_memstream is opened only if tracks_count != 0. */
+    if (vlc_memstream_close(&stream) != 0)
+        return;
+
+    if (tracks_count == 1)
+        vlc_player_osd_Message(player, _("%s track: %s"), cat_name,
+                               stream.ptr);
+    else
+        vlc_player_osd_Message(player, _("%s tracks: %s"), cat_name,
+                               stream.ptr);
+    free(stream.ptr);
 }
 
 void



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/10e096a3a5b358a14d5728ff1b19c849912cae00...da50ca644c97b74d4c15166d8e11fd72cf67b952

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/10e096a3a5b358a14d5728ff1b19c849912cae00...da50ca644c97b74d4c15166d8e11fd72cf67b952
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list