mxnet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] cjolivier01 commented on a change in pull request #9370: Fix crash when opening an image, fix exception safety.
Date Thu, 01 Jan 1970 00:00:00 GMT
cjolivier01 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_r161564876
 
 

 ##########
 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:
   unsafe code? i?m not sure what you?re referring to. make_shared or uniqe_ptr will cause
the buffer to be deleted. what are you claiming is ?unsafe?.
   by the way, performance is a big deal.

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

Mime
View raw message