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/12 18:47:49 UTC

[GitHub] cjolivier01 commented on a change in pull request #9370: Fix leak, fix crash, fix exception safety.

cjolivier01 commented on a change in pull request #9370: Fix leak, fix crash, fix exception safety.
URL: https://github.com/apache/incubator-mxnet/pull/9370#discussion_r161296975
 
 

 ##########
 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:
   Using vector here unnecessary and is undesirable for a couple of reasons:
   1) You don't need any high-level vector functionality.
   2) It increases the compile time because templates are expensive to compile.
   3) For some (or maybe all) implementations, the constructor will initialize all values, which are subsequently overwritten

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