History

stream_blurary: consistently cleanup on error

Sometimes there was an immediate return on error and other times it destroyed things before returning the error. Make this consistent whenever something fails while we open. Also remove the destruct function since it is completely redundant with bluray_stream_close.

Dudemanguy committed 1 year ago

Commit affea091 parent e20e0001 file · +23 −15Browse files

Unified · Split

stream/stream_bluray.c+23−15
@@ -104,13 +104,6 @@ struct bluray_priv_s { · 103 unmodified lines
104104 struct m_config_cache *opts_cache;
105105 };
106106
107−static void destruct(struct bluray_priv_s *priv)
108−{
109− if (priv->title_info)
110− bd_free_title_info(priv->title_info);
111− bd_close(priv->bd);
112−}
113−
114107 inline static int play_playlist(struct bluray_priv_s *priv, int playlist)
115108 {
116109 return bd_select_playlist(priv->bd, playlist);
@@ -123,7 +116,14 @@ inline static int play_title(struct bluray_priv_s *priv, int title) · 6 unmodified lines
123116
124117 static void bluray_stream_close(stream_t *s)
125118 {
126− destruct(s->priv);
119+ struct bluray_priv_s *priv = s->priv;
120+ if (!priv)
121+ return;
122+
123+ if (priv->title_info)
124+ bd_free_title_info(priv->title_info);
125+ if (priv->bd)
126+ bd_close(priv->bd);
127127 }
128128
129129 static void handle_event(stream_t *s, const BD_EVENT *ev)
@@ -408,6 +408,7 @@ static int bluray_stream_open_internal(stream_t *s) · 278 unmodified lines
408408 {
409409 struct bluray_priv_s *b = s->priv;
410410
411+ int ret = 0;
411412 char *device = NULL;
412413 /* find the requested device */
413414 if (b->cfg_device && b->cfg_device[0]) {
@@ -418,7 +419,8 @@ static int bluray_stream_open_internal(stream_t *s) · 4 unmodified lines
418419
419420 if (!device || !device[0]) {
420421 MP_ERR(s, "No Blu-ray device/location was specified ...\n");
421− return STREAM_UNSUPPORTED;
422+ ret = STREAM_UNSUPPORTED;
423+ goto err;
422424 }
423425
424426 if (!mp_msg_test(s->log, MSGL_DEBUG))
@@ -430,26 +432,28 @@ static int bluray_stream_open_internal(stream_t *s) · 5 unmodified lines
430432 talloc_free(device_tmp);
431433 if (!bd) {
432434 MP_ERR(s, "Couldn't open Blu-ray device: %s\n", device);
433− return STREAM_UNSUPPORTED;
435+ ret = STREAM_UNSUPPORTED;
436+ goto err;
434437 }
435438 b->bd = bd;
436439
437440 if (!check_disc_info(s)) {
438− destruct(b);
439− return STREAM_UNSUPPORTED;
441+ ret = STREAM_UNSUPPORTED;
442+ goto err;
440443 }
441444
442445 int title_guess = BLURAY_DEFAULT_TITLE;
443446 if (b->use_nav) {
444447 MP_FATAL(s, "BluRay menu support has been removed.\n");
445− return STREAM_ERROR;
448+ ret = STREAM_ERROR;
449+ goto err;
446450 } else {
447451 /* check for available titles on disc */
448452 b->num_titles = bd_get_titles(bd, TITLES_RELEVANT, 0);
449453 if (!b->num_titles) {
450454 MP_ERR(s, "Can't find any Blu-ray-compatible title here.\n");
451− destruct(b);
452− return STREAM_UNSUPPORTED;
455+ ret = STREAM_UNSUPPORTED;
456+ goto err;
453457 }
454458
455459 MP_INFO(s, "List of available titles:\n");
@@ -494,6 +498,10 @@ static int bluray_stream_open_internal(stream_t *s) · 38 unmodified lines
494498 MP_VERBOSE(s, "Blu-ray successfully opened.\n");
495499
496500 return STREAM_OK;
501+
502+err:
503+ bluray_stream_close(s);
504+ return ret;
497505 }
498506
499507 const stream_info_t stream_info_bdnav;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t