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.
Unified · Split
| @@ -104,13 +104,6 @@ struct bluray_priv_s { · 103 unmodified lines | ||
| 104 | 104 | struct m_config_cache *opts_cache; |
| 105 | 105 | }; |
| 106 | 106 | |
| 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 | − | |
| 114 | 107 | inline static int play_playlist(struct bluray_priv_s *priv, int playlist) |
| 115 | 108 | { |
| 116 | 109 | 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 | ||
| 123 | 116 | |
| 124 | 117 | static void bluray_stream_close(stream_t *s) |
| 125 | 118 | { |
| 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); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | 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 | ||
| 408 | 408 | { |
| 409 | 409 | struct bluray_priv_s *b = s->priv; |
| 410 | 410 | |
| 411 | + int ret = 0; | |
| 411 | 412 | char *device = NULL; |
| 412 | 413 | /* find the requested device */ |
| 413 | 414 | if (b->cfg_device && b->cfg_device[0]) { |
| @@ -418,7 +419,8 @@ static int bluray_stream_open_internal(stream_t *s) · 4 unmodified lines | ||
| 418 | 419 | |
| 419 | 420 | if (!device || !device[0]) { |
| 420 | 421 | MP_ERR(s, "No Blu-ray device/location was specified ...\n"); |
| 421 | − return STREAM_UNSUPPORTED; | |
| 422 | + ret = STREAM_UNSUPPORTED; | |
| 423 | + goto err; | |
| 422 | 424 | } |
| 423 | 425 | |
| 424 | 426 | if (!mp_msg_test(s->log, MSGL_DEBUG)) |
| @@ -430,26 +432,28 @@ static int bluray_stream_open_internal(stream_t *s) · 5 unmodified lines | ||
| 430 | 432 | talloc_free(device_tmp); |
| 431 | 433 | if (!bd) { |
| 432 | 434 | MP_ERR(s, "Couldn't open Blu-ray device: %s\n", device); |
| 433 | − return STREAM_UNSUPPORTED; | |
| 435 | + ret = STREAM_UNSUPPORTED; | |
| 436 | + goto err; | |
| 434 | 437 | } |
| 435 | 438 | b->bd = bd; |
| 436 | 439 | |
| 437 | 440 | if (!check_disc_info(s)) { |
| 438 | − destruct(b); | |
| 439 | − return STREAM_UNSUPPORTED; | |
| 441 | + ret = STREAM_UNSUPPORTED; | |
| 442 | + goto err; | |
| 440 | 443 | } |
| 441 | 444 | |
| 442 | 445 | int title_guess = BLURAY_DEFAULT_TITLE; |
| 443 | 446 | if (b->use_nav) { |
| 444 | 447 | MP_FATAL(s, "BluRay menu support has been removed.\n"); |
| 445 | − return STREAM_ERROR; | |
| 448 | + ret = STREAM_ERROR; | |
| 449 | + goto err; | |
| 446 | 450 | } else { |
| 447 | 451 | /* check for available titles on disc */ |
| 448 | 452 | b->num_titles = bd_get_titles(bd, TITLES_RELEVANT, 0); |
| 449 | 453 | if (!b->num_titles) { |
| 450 | 454 | 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; | |
| 453 | 457 | } |
| 454 | 458 | |
| 455 | 459 | MP_INFO(s, "List of available titles:\n"); |
| @@ -494,6 +498,10 @@ static int bluray_stream_open_internal(stream_t *s) · 38 unmodified lines | ||
| 494 | 498 | MP_VERBOSE(s, "Blu-ray successfully opened.\n"); |
| 495 | 499 | |
| 496 | 500 | return STREAM_OK; |
| 501 | + | |
| 502 | +err: | |
| 503 | + bluray_stream_close(s); | |
| 504 | + return ret; | |
| 497 | 505 | } |
| 498 | 506 | |
| 499 | 507 | const stream_info_t stream_info_bdnav; |