Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
05761dd3 by Steve Lhomme at 2023-11-28T06:35:20+00:00
modules: fix vlc_memstream_close success checks

It doesn't return VLC_SUCCESS but 0 (even though it's the same thing).

- - - - -
b23c4e71 by Steve Lhomme at 2023-11-28T06:35:20+00:00
win32/spawn: use a regular string for application_name

We only need to free if it was not set to the path parameter.

- - - - -
18b08d1e by Steve Lhomme at 2023-11-28T06:35:20+00:00
win32/spawn: use a regular string for cmdline

We can handle the memstream locally and exit on error.

- - - - -
932a1c3e by Steve Lhomme at 2023-11-28T06:35:20+00:00
webvtt: don't reset empty memstream pointer

The content is later used with vlc_memstream_write. Passing NULL is undefined.
On Windows it uses fwrite which doesn't allow passing NULL [1].

[1] https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/fwrite

- - - - -
a3749aa6 by Steve Lhomme at 2023-11-28T06:35:20+00:00
memstream: do nothing when writing a length of 0

- - - - -
02b47bc2 by Steve Lhomme at 2023-11-28T06:35:20+00:00
core: set VLC_MALLOC on strings allocated by a memstream

After vlc_memstream_close() the memstream cannot be used anymore.

- - - - -
e52cc89f by Steve Lhomme at 2023-11-28T06:35:20+00:00
modules: set VLC_MALLOC on strings allocated by a memstream

After vlc_memstream_close() the memstream cannot be used anymore.

- - - - -
6c9543c4 by Steve Lhomme at 2023-11-28T06:35:20+00:00
mrl_helpers: return the escaped string in mrl_EscapeFragmentIdentifier

We don't need an error code.

- - - - -
2746c42e by Steve Lhomme at 2023-11-28T06:35:20+00:00
gl_util: free the source earlier

We don't need to wait when closing the memstream.

- - - - -


20 changed files:

- include/vlc_strings.h
- modules/access/http/message.h
- modules/access/smb2.c
- modules/codec/webvtt/subsvtt.c
- modules/demux/playlist/asx.c
- modules/demux/ttml.c
- modules/demux/webvtt.c
- modules/keystore/kwallet.c
- modules/stream_out/es.c
- modules/stream_out/hls/hls.c
- modules/video_output/opengl/gl_util.c
- src/input/es_out.c
- src/input/mrl_helpers.h
- src/input/stream_extractor.c
- src/input/vlmshell.c
- src/player/player.h
- src/test/mrl_helpers.c
- src/text/memstream.c
- src/text/url.c
- src/win32/spawn.c


Changes:

=====================================
include/vlc_strings.h
=====================================
@@ -223,7 +223,7 @@ VLC_API char *vlc_strftime( const char * );
  * \return an allocated formatted string (must be free()'d), or NULL in case 
of error
  */
 VLC_API char *vlc_strfplayer( vlc_player_t *player, input_item_t *item,
-                              const char *fmt );
+                              const char *fmt ) VLC_MALLOC;
 
 static inline char *str_format( vlc_player_t *player, input_item_t *item,
                                 const char *fmt )


=====================================
modules/access/http/message.h
=====================================
@@ -459,7 +459,7 @@ static inline void vlc_http_stream_close(struct 
vlc_http_stream *s, bool abort)
  *         or NULL on error
  */
 char *vlc_http_msg_format(const struct vlc_http_msg *m, size_t *restrict lenp,
-                          bool proxied, bool chunked) VLC_USED;
+                          bool proxied, bool chunked) VLC_USED VLC_MALLOC;
 
 /**
  * Parses an HTTP 1.1 message header.


=====================================
modules/access/smb2.c
=====================================
@@ -383,7 +383,7 @@ FileControl(stream_t *access, int i_query, va_list args)
     return VLC_SUCCESS;
 }
 
-static char *
+VLC_MALLOC static char *
 vlc_smb2_get_url(vlc_url_t *url, const char *file)
 {
     /* smb2://<psz_host><i_port><psz_path><file>?<psz_option> */
@@ -429,7 +429,7 @@ static int AddItem(stream_t *access, struct 
vlc_readdir_helper *rdh,
     if (url == NULL)
         return VLC_ENOMEM;
 
-    input_item_t *p_item; 
+    input_item_t *p_item;
     int ret = vlc_readdir_helper_additem(rdh, url, NULL, name, i_type,
                                          ITEM_NET, &p_item);
 


=====================================
modules/codec/webvtt/subsvtt.c
=====================================
@@ -2019,7 +2019,7 @@ static void ParserHeaderHandler( void *priv, enum 
webvtt_header_line_e s,
 #ifdef HAVE_CSS
         else if( ctx->b_css_memstream_opened )
         {
-            if( vlc_memstream_close( &ctx->css ) == VLC_SUCCESS )
+            if( vlc_memstream_close( &ctx->css ) == 0 )
             {
                 vlc_css_parser_t p;
                 vlc_css_parser_Init(&p);


=====================================
modules/demux/playlist/asx.c
=====================================
@@ -437,7 +437,7 @@ static void memstream_puts_xmlencoded(struct vlc_memstream* 
p_stream, const char
  *  - make tags and attributes upercase
  *  - escape strings when required
  */
-static char* ASXToXML( char* psz_source )
+VLC_MALLOC static char* ASXToXML( char* psz_source )
 {
     bool b_in_string= false;
     char *psz_source_cur = psz_source;


=====================================
modules/demux/ttml.c
=====================================
@@ -377,7 +377,7 @@ static int Demux( demux_t* p_demux )
         tt_node_ToText( &stream, (tt_basenode_t *) p_sys->p_rootnode,
                         &p_sys->times.p_array[p_sys->times.i_current] );
 
-        if( vlc_memstream_close( &stream ) == VLC_SUCCESS )
+        if( vlc_memstream_close( &stream ) == 0 )
         {
             block_t* p_block = block_heap_Alloc( stream.ptr, stream.length );
             if( p_block )
@@ -523,7 +523,7 @@ int tt_OpenDemux( vlc_object_t* p_this )
 
         vlc_memstream_putc( &stream, '\0' );
 
-        if( vlc_memstream_close( &stream ) == VLC_SUCCESS )
+        if( vlc_memstream_close( &stream ) == 0 )
         {
             msg_Dbg( p_demux, "%s", stream.ptr );
             free( stream.ptr );


=====================================
modules/demux/webvtt.c
=====================================
@@ -132,10 +132,9 @@ static block_t *ConvertWEBVTT( const webvtt_cue_t *p_cue, 
bool b_continued )
     vlc_memstream_write( &stream, paylbox, 8 );
     vlc_memstream_write( &stream, p_cue->psz_text, paylsize - 8 );
 
-    if( vlc_memstream_close( &stream ) == VLC_SUCCESS )
+    if( vlc_memstream_close( &stream ) == 0 )
         return block_heap_Alloc( stream.ptr, stream.length );
-    else
-        return NULL;
+    return NULL;
 }
 
 struct memstream_wrap
@@ -155,13 +154,8 @@ static void memstream_Append( struct memstream_wrap *mw, 
const char *psz )
 
 static void memstream_Grab( struct memstream_wrap *mw, void **pp, size_t *pi )
 {
-    if( mw->b_opened && vlc_memstream_close( &mw->memstream ) == VLC_SUCCESS )
+    if( mw->b_opened && vlc_memstream_close( &mw->memstream ) == 0 )
     {
-        if( mw->memstream.length == 0 )
-        {
-            free( mw->memstream.ptr );
-            mw->memstream.ptr = NULL;
-        }
         *pp = mw->memstream.ptr;
         *pi = mw->memstream.length;
     }
@@ -418,7 +412,7 @@ static void MakeExtradata( demux_sys_t *p_sys, void 
**p_extra, size_t *pi_extra
                                      p_sys->regions_headers.i_data );
     vlc_memstream_write( &extradata, p_sys->styles_headers.p_data,
                                      p_sys->styles_headers.i_data );
-    if( vlc_memstream_close( &extradata ) == VLC_SUCCESS )
+    if( vlc_memstream_close( &extradata ) == 0 )
     {
         if( extradata.length )
         {


=====================================
modules/keystore/kwallet.c
=====================================
@@ -108,7 +108,7 @@ typedef struct vlc_keystore_sys
 
 /* takes all values in the values of vlc_keystore_entry *
  * and formats them in a url key */
-static char*
+VLC_MALLOC static char*
 values2key( const char* const* ppsz_values, bool b_search )
 {
     char* psz_b64_realm = NULL;


=====================================
modules/stream_out/es.c
=====================================
@@ -62,8 +62,8 @@ typedef struct
     bool synchronous;
 } sout_stream_id_sys_t;
 
-static char * es_print_url( const char *psz_fmt, vlc_fourcc_t i_fourcc, int 
i_count,
-                            const char *psz_access, const char *psz_mux )
+VLC_MALLOC static char * es_print_url( const char *psz_fmt, vlc_fourcc_t 
i_fourcc, int i_count,
+                                       const char *psz_access, const char 
*psz_mux )
 {
     struct vlc_memstream stream;
     unsigned char c;


=====================================
modules/stream_out/hls/hls.c
=====================================
@@ -213,8 +213,8 @@ static inline hls_track_t *MediaGetTrack(const 
hls_playlist_t *media_playlist)
     return track;
 }
 
-static char *GeneratePlaylistCodecInfo(const struct vlc_list *media_list,
-                                       const hls_playlist_t *playlist)
+VLC_MALLOC static char *GeneratePlaylistCodecInfo(const struct vlc_list 
*media_list,
+                                                  const hls_playlist_t 
*playlist)
 {
     es_format_vec_t already_described = VLC_VECTOR_INITIALIZER;
 


=====================================
modules/video_output/opengl/gl_util.c
=====================================
@@ -70,17 +70,16 @@ LogShader(vlc_object_t *obj, const char *prefix, const 
opengl_vtable_t *vt, GLui
         }
         line++;
     }
+    free(sources);
 
     ret = vlc_memstream_close(&stream);
     if (ret != 0)
     {
-        free(sources);
         return;
     }
 
     msg_Err(obj, "%s%s", prefix, stream.ptr);
     free(stream.ptr);
-    free(sources);
 }
 
 static void


=====================================
src/input/es_out.c
=====================================
@@ -1991,8 +1991,8 @@ static void EsOutFillEsFmt(es_out_t *out, es_format_t 
*fmt)
     }
 }
 
-static char *EsOutCreateStrId( es_out_id_t *es, bool stable, const char *id,
-                               es_out_id_t *p_master )
+VLC_MALLOC static char *EsOutCreateStrId( es_out_id_t *es, bool stable, const 
char *id,
+                                          es_out_id_t *p_master )
 {
     struct vlc_memstream ms;
     if( vlc_memstream_open( &ms ) != 0 )


=====================================
src/input/mrl_helpers.h
=====================================
@@ -49,13 +49,11 @@
  * See the \link mrl MRL-specification\endlink for a detailed
  * explanation of how `payload` will be escaped.
  *
- * \param[out] out `*out` will refer to the created string on success,
- *                  and an unspecified value on error.
  * \param[in] payload the data to escape.
- * \return VLC_SUCCESS on success, an error-code on failure.
+ * \return he created string on success, and NULL on error.
  **/
-static inline int
-mrl_EscapeFragmentIdentifier( char** out, char const* payload )
+VLC_MALLOC static inline char *
+mrl_EscapeFragmentIdentifier( char const* payload )
 {
     struct vlc_memstream mstream;
 
@@ -69,7 +67,7 @@ mrl_EscapeFragmentIdentifier( char** out, char const* payload 
)
 #define RFC3986_FRAGMENT   RFC3986_PCHAR "/" "?"
 
     if( vlc_memstream_open( &mstream ) )
-        return VLC_EGENERIC;
+        return NULL;
 
     for( char const* p = payload; *p; ++p )
     {
@@ -86,10 +84,9 @@ mrl_EscapeFragmentIdentifier( char** out, char const* 
payload )
 #undef RFC3986_SUBDELIMS
 
     if( vlc_memstream_close( &mstream ) )
-        return VLC_EGENERIC;
+        return NULL;
 
-    *out = mstream.ptr;
-    return VLC_SUCCESS;
+    return mstream.ptr;
 }
 
 /**


=====================================
src/input/stream_extractor.c
=====================================
@@ -86,13 +86,14 @@ struct stream_extractor_private {
  * within \p base, see \ref mrl_helpers for further information.
  **/
 
-static char*
+VLC_MALLOC static char*
 StreamExtractorCreateMRL( char const* base, char const* subentry )
 {
     struct vlc_memstream buffer;
     char* escaped;
 
-    if( mrl_EscapeFragmentIdentifier( &escaped, subentry ) )
+    escaped = mrl_EscapeFragmentIdentifier( subentry );
+    if ( escaped == NULL )
         return NULL;
 
     if( vlc_memstream_open( &buffer ) )


=====================================
src/input/vlmshell.c
=====================================
@@ -64,7 +64,7 @@ static vlm_message_t *vlm_Show( vlm_t *, vlm_media_sys_t *, 
vlm_schedule_sys_t *
 
 static vlm_schedule_sys_t *vlm_ScheduleSearch( vlm_t *, const char * );
 
-static char *Save( vlm_t * );
+VLC_MALLOC static char *Save( vlm_t * );
 static int Load( vlm_t *, char * );
 
 static vlm_schedule_sys_t *vlm_ScheduleNew( vlm_t *vlm, const char *psz_name );
@@ -1573,7 +1573,7 @@ static int Load( vlm_t *vlm, char *file )
     return 0;
 }
 
-static char *Save( vlm_t *vlm )
+VLC_MALLOC static char *Save( vlm_t *vlm )
 {
     const char *psz_header = "\n"
                              "# VLC media player VLM command batch\n"


=====================================
src/player/player.h
=====================================
@@ -434,7 +434,7 @@ vlc_player_input_SelectTracksByStringIds(struct 
vlc_player_input *input,
 
 char *
 vlc_player_input_GetSelectedTrackStringIds(struct vlc_player_input *input,
-                                           enum es_format_category_e cat);
+                                           enum es_format_category_e cat) 
VLC_MALLOC;
 
 vlc_tick_t
 vlc_player_input_GetTime(struct vlc_player_input *input);


=====================================
src/test/mrl_helpers.c
=====================================
@@ -91,9 +91,8 @@ int main (void)
 
                 assert(strcmp(testcase[i].results[j], res) == 0);
 
-                char *res_escaped = NULL;
-                ret = mrl_EscapeFragmentIdentifier(&res_escaped, res);
-                assert(ret == VLC_SUCCESS && res_escaped != NULL);
+                char *res_escaped = mrl_EscapeFragmentIdentifier(res);
+                assert(res_escaped != NULL);
                 assert(strncmp(p, res_escaped, strlen(res_escaped)) == 0);
                 p += strlen(res_escaped) + 2;
 


=====================================
src/text/memstream.c
=====================================
@@ -71,6 +71,9 @@ size_t vlc_memstream_write(struct vlc_memstream *ms, const 
void *ptr,
     if (unlikely(ms->stream == NULL))
         return 0;
 
+    if (len == 0)
+        return 0;
+
     return fwrite(ptr, 1, len, ms->stream);
 }
 
@@ -129,6 +132,9 @@ size_t vlc_memstream_write(struct vlc_memstream *ms, const 
void *ptr,
 {
     size_t newlen;
 
+    if (len == 0)
+        return 0;
+
     if (unlikely(add_overflow(ms->length, len, &newlen))
      || unlikely(add_overflow(newlen, 1, &newlen)))
         goto error;


=====================================
src/text/url.c
=====================================
@@ -856,7 +856,7 @@ error:
     return ret;
 }
 
-static char *vlc_uri_fixup_inner(const char *str, const char *extras)
+VLC_MALLOC static char *vlc_uri_fixup_inner(const char *str, const char 
*extras)
 {
     assert(str && extras);
 


=====================================
src/win32/spawn.c
=====================================
@@ -112,15 +112,8 @@ static int vlc_spawn_inner(pid_t *restrict pid, const char 
*path,
         }
     };
 
-    struct vlc_memstream application_name;
-    struct vlc_memstream cmdline;
-    {
-        int error;
-        error = vlc_memstream_open(&application_name);
-        error |= vlc_memstream_open(&cmdline);
-        if (unlikely(error))
-            goto error;
-    }
+    const char *application_name = NULL;
+    char *cmdline = NULL;
 
     if (fdv[0] == -1 || fdv[1] == -1) {
         nulfd = vlc_open("\\\\.\\NUL", O_RDWR);
@@ -175,20 +168,25 @@ static int vlc_spawn_inner(pid_t *restrict pid, const 
char *path,
             goto error;
         }
 
-        vlc_memstream_printf(&application_name, "%s", application_path);
-        free(application_path);
+        application_name = application_path;
 
     } else {
-        vlc_memstream_printf(&application_name, "%s", path);
+        application_name = path;
     }
 
     if (likely(argv[0])) {
-        vlc_memstream_printf(&cmdline, "%s", argv[0]);
+        struct vlc_memstream cmdline_s;
+        if (unlikely(vlc_memstream_open(&cmdline_s) != 0))
+            goto error;
+        vlc_memstream_printf(&cmdline_s, "%s", argv[0]);
         for (int argc = 1; argv[argc]; ++argc)
-            vlc_memstream_printf(&cmdline, " %s", argv[argc]);
+            vlc_memstream_printf(&cmdline_s, " %s", argv[argc]);
+        if (vlc_memstream_close(&cmdline_s) != 0)
+            goto error;
+        cmdline = cmdline_s.ptr;
     }
 
-    BOOL bSuccess = CreateProcessA(application_name.ptr, cmdline.ptr, NULL,
+    BOOL bSuccess = CreateProcessA(application_name, cmdline, NULL,
                                    NULL, TRUE, EXTENDED_STARTUPINFO_PRESENT,
                                    NULL, NULL, &siEx.StartupInfo, &pi);
     if (!bSuccess)
@@ -222,10 +220,9 @@ error:
         free(siEx.lpAttributeList);
     }
 
-    if (!vlc_memstream_close(&application_name))
-        free(application_name.ptr);
-    if (!vlc_memstream_close(&cmdline))
-        free(cmdline.ptr);
+    if (application_name != path)
+        free((char*)application_name);
+    free(cmdline);
 
     return ret;
 }



View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/compare/1fa7526be4e6b8d8e11a1be1a92a7573cbb45d22...2746c42e295dcf0ae333c3f26cd44ebbfff3218c

-- 
View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/compare/1fa7526be4e6b8d8e11a1be1a92a7573cbb45d22...2746c42e295dcf0ae333c3f26cd44ebbfff3218c
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance
_______________________________________________
vlc-commits mailing list
vlc-commits@videolan.org
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to