[vlc-commits] [Git][videolan/vlc][master] 3 commits: sap: rework `CreateAnnounce` error path
Steve Lhomme (@robUx4)
gitlab at videolan.org
Wed Nov 22 10:45:33 UTC 2023
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
810186c3 by Alaric Senat at 2023-11-22T10:30:32+00:00
sap: rework `CreateAnnounce` error path
This fixes leaks on error cases.
- - - - -
6fe397b5 by Alaric Senat at 2023-11-22T10:30:32+00:00
sap: fix input item URI leak
`input_item_NewStream` does not take ownership of the allocated string.
- - - - -
ff44904b by Alaric Senat at 2023-11-22T10:30:32+00:00
sap: use `input_item_SetMeta`
Instead of overriding the input metadata directly. This saves an
allocation and fix the previously allocated metadata leak.
- - - - -
1 changed file:
- modules/services_discovery/sap.c
Changes:
=====================================
modules/services_discovery/sap.c
=====================================
@@ -148,19 +148,17 @@ static sap_announce_t *CreateAnnounce(services_discovery_t *p_sd,
if (p_sdp == NULL)
return NULL;
+ sap_announce_t *p_sap = malloc(sizeof (*p_sap));
+ if( p_sap == NULL )
+ goto error;
+
char *uri = NULL;
if (asprintf(&uri, "sdp://%s", psz_sdp) == -1)
- {
- vlc_sdp_free(p_sdp);
- return NULL;
- }
+ goto error;
input_item_t *p_input;
const char *psz_value;
- sap_announce_t *p_sap = malloc(sizeof (*p_sap));
- if( p_sap == NULL )
- return NULL;
p_sap->i_last = vlc_tick_now();
p_sap->i_period = 0;
@@ -171,19 +169,13 @@ static sap_announce_t *CreateAnnounce(services_discovery_t *p_sd,
/* Released in RemoveAnnounce */
p_input = input_item_NewStream(uri, p_sdp->name,
INPUT_DURATION_INDEFINITE);
+ free(uri);
if( unlikely(p_input == NULL) )
- {
- free( p_sap );
- return NULL;
- }
+ goto error;
+
p_sap->p_item = p_input;
- vlc_meta_t *p_meta = vlc_meta_New();
- if( likely(p_meta != NULL) )
- {
- vlc_meta_Set(p_meta, vlc_meta_Description, p_sdp->info);
- p_input->p_meta = p_meta;
- }
+ input_item_SetMeta(p_input, vlc_meta_Description, p_sdp->info);
psz_value = vlc_sdp_attr_value(p_sdp, "tool");
if( psz_value != NULL )
@@ -213,6 +205,10 @@ static sap_announce_t *CreateAnnounce(services_discovery_t *p_sd,
vlc_sdp_free(p_sdp);
return p_sap;
+error:
+ free(p_sap);
+ vlc_sdp_free(p_sdp);
+ return NULL;
}
typedef struct
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/1ccff8cc090dd803ea849181ac725e7691f4dd5f...ff44904b5a74c71d59efc3d7cc38fd2a1985f920
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/1ccff8cc090dd803ea849181ac725e7691f4dd5f...ff44904b5a74c71d59efc3d7cc38fd2a1985f920
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