Cancelling "fix by netfabb" may leave output file handler to a temp file

opened. This is fixed now.

Fixes Memory leak when exporting to netfabb and cancelling #7632
This commit is contained in:
Vojtech Bubnik 2022-01-04 17:29:17 +01:00
parent b5c45762c9
commit 3aad2a9f4a

View File

@ -284,7 +284,7 @@ void fix_model_by_win10_sdk(const std::string &path_src, const std::string &path
// Open the destination file. // Open the destination file.
FILE *fout = boost::nowide::fopen(path_dst.c_str(), "wb"); FILE *fout = boost::nowide::fopen(path_dst.c_str(), "wb");
try {
Microsoft::WRL::ComPtr<ABI::Windows::Storage::Streams::IBuffer> buffer; Microsoft::WRL::ComPtr<ABI::Windows::Storage::Streams::IBuffer> buffer;
byte *buffer_ptr; byte *buffer_ptr;
bufferFactory->Create(65536 * 2048, buffer.GetAddressOf()); bufferFactory->Create(65536 * 2048, buffer.GetAddressOf());
@ -295,7 +295,6 @@ void fix_model_by_win10_sdk(const std::string &path_src, const std::string &path
} }
uint32_t length; uint32_t length;
hr = buffer->get_Length(&length); hr = buffer->get_Length(&length);
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncOperationWithProgress<ABI::Windows::Storage::Streams::IBuffer*, UINT32>> asyncRead; Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncOperationWithProgress<ABI::Windows::Storage::Streams::IBuffer*, UINT32>> asyncRead;
for (;;) { for (;;) {
hr = inputStream->ReadAsync(buffer.Get(), 65536 * 2048, ABI::Windows::Storage::Streams::InputStreamOptions_ReadAhead, asyncRead.GetAddressOf()); hr = inputStream->ReadAsync(buffer.Get(), 65536 * 2048, ABI::Windows::Storage::Streams::InputStreamOptions_ReadAhead, asyncRead.GetAddressOf());
@ -307,6 +306,10 @@ void fix_model_by_win10_sdk(const std::string &path_src, const std::string &path
break; break;
fwrite(buffer_ptr, length, 1, fout); fwrite(buffer_ptr, length, 1, fout);
} }
} catch (...) {
fclose(fout);
throw;
}
fclose(fout); fclose(fout);
// Here all the COM objects will be released through the ComPtr destructors. // Here all the COM objects will be released through the ComPtr destructors.
} }