Fix the memory issue in ov_core_read_model_from_memory (#12817)

This commit is contained in:
RICKIE777 2022-09-07 14:06:31 +08:00 committed by GitHub
parent a092a192d8
commit f780303e5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -41,10 +41,11 @@ inline static std::vector<uint8_t> content_from_file(const char* filename, bool
std::ifstream is(filename, is_binary ? std::ifstream::binary | std::ifstream::in : std::ifstream::in);
if (is) {
is.seekg(0, std::ifstream::end);
result.resize(is.tellg());
if (result.size() > 0) {
size_t file_len = is.tellg();
result.resize(file_len + 1);
if (file_len > 0) {
is.seekg(0, std::ifstream::beg);
is.read(reinterpret_cast<char*>(&result[0]), result.size());
is.read(reinterpret_cast<char*>(&result[0]), file_len);
}
}
}