Skip to content

Commit

Permalink
Fixed crashes caused by the resource leak of mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
windows-server-2003 committed Nov 28, 2021
1 parent 4022e99 commit edeff32
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/network/network_downloader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ struct NetworkStream {
bool livestream_eof = false;
bool livestream_private = false;

~NetworkStream();

// if `whole_download` is true, it will not use Range request but download the whole content at once (used for livestreams)
NetworkStream (std::string url, bool whole_download, NetworkSessionList *session_list);

Expand Down
15 changes: 14 additions & 1 deletion source/network/network_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,11 @@ void NetworkDecoder::deinit() {
free(sw_video_output_tmp);
sw_video_output_tmp = NULL;

if (buffered_pts_list_lock) {
svcCloseHandle(buffered_pts_list_lock);
buffered_pts_list_lock = 0;
}

// ffmpeg data should not be freed, but to prevent accesses to them, we set NULLs here
for (int type = 0; type < 2; type++) {
network_stream[type] = NULL;
Expand Down Expand Up @@ -519,11 +524,19 @@ Result_with_string NetworkDecoder::init_output_buffer(bool is_mvd) {

Result_with_string NetworkDecoder::init(bool request_hw_decoder) {
Result_with_string result;
Result libctru_result;

hw_decoder_enabled = request_hw_decoder;
interrupt = false;

svcCreateMutex(&buffered_pts_list_lock, false);
libctru_result = svcCreateMutex(&buffered_pts_list_lock, false);
if (libctru_result != 0) {
Util_log_save("debug", "decoder mutex fail");
usleep(1000000);
result.code = libctru_result;
result.error_description = "Failed to create mutex";
return result;
}

if (!audio_only) {
result = init_output_buffer(request_hw_decoder);
Expand Down
4 changes: 4 additions & 0 deletions source/network/network_downloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
NetworkStream::NetworkStream(std::string url, bool whole_download, NetworkSessionList *session_list) : url(url), whole_download(whole_download), session_list(session_list) {
svcCreateMutex(&downloaded_data_lock, false);
}
NetworkStream::~NetworkStream() {
svcCloseHandle(downloaded_data_lock);
downloaded_data_lock = 0;
}
bool NetworkStream::is_data_available(u64 start, u64 size) {
if (!ready) return false;
if (start + size > len) return false;
Expand Down

0 comments on commit edeff32

Please sign in to comment.