piiswrong commented on a change in pull request #9370: Fix crash when opening an image, fix exception safety. URL: https://github.com/apache/incubator-mxnet/pull/9370#discussion_r161602056
########## File path: src/io/image_io.cc ########## @@ -218,29 +218,29 @@ void Imread(const nnvm::NodeAttrs& attrs, const auto& param = nnvm::get<ImreadParam>(attrs.parsed); std::ifstream file(param.filename, std::ios::binary | std::ios::ate); + // if file is not open we get bad alloc after tellg + CHECK(file.is_open()) << "Imread: Couldn't open file: " << param.filename; size_t fsize = file.tellg(); file.seekg(0, std::ios::beg); - auto buff = new uint8_t[fsize]; - file.read(reinterpret_cast<char*>(buff), fsize); + auto buff = std::make_shared<std::vector<uint8_t> >(fsize); Review comment: shared_ptr can be replaced with a move capture. but I think its only available since c++14. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
