You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/01/15 16:49:32 UTC

[GitHub] larroy commented on a change in pull request #9370: Fix crash when opening an image, fix exception safety.

larroy 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_r161570494
 
 

 ##########
 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:
   Could you please explicitly type out how do you propose to allocate this buffer?
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services