diff --git a/src/common/util.cpp b/src/common/util.cpp index 1ed19b6cd8e360e127b2c96cc5379dc7a222bb17..728653ecf03897d4a4aefe01bfcfefe1a07a47a2 100644 --- a/src/common/util.cpp +++ b/src/common/util.cpp @@ -14,6 +14,8 @@ limitations under the License. */ #include "common/util.h" +namespace paddle_mobile { + char *ReadFileToBuff(std::string filename) { FILE *file = fopen(filename.c_str(), "rb"); PADDLE_MOBILE_ENFORCE(file != nullptr, "can't open file: %s ", @@ -29,3 +31,5 @@ char *ReadFileToBuff(std::string filename) { fclose(file); return data; } + +} // namespace paddle_mobile diff --git a/src/io/executor.cpp b/src/io/executor.cpp index 19d273af6dce6d9233e889aff7ac1b354b033197..5d3d3525812bfb5ad1646f7354bbd68193c9a78c 100644 --- a/src/io/executor.cpp +++ b/src/io/executor.cpp @@ -161,10 +161,11 @@ void Executor::InitMemory() { if (var_desc->Name() == "feed" || var_desc->Name() == "fetch") { continue; } - char *data = + char *origin_data = ReadFileToBuff(program_.model_path + "/" + var_desc->Name()); + char *data = origin_data; LoadMemory((void**)&data, var_desc, tensor); - delete [] data; + delete [] origin_data; } else { if (var_desc->Type() == framework::VARTYPE_TYPE_LOD_TENSOR) { varInputMemory(var_desc, var, tensor); @@ -176,15 +177,16 @@ void Executor::InitMemory() { template void Executor::InitCombineMemory() { - char *data = nullptr; + char *origin_data = nullptr; bool self_alloc = false; if (program_.combined_params_buf && program_.combined_params_len) { - data = (char *)program_.combined_params_buf; + origin_data = (char *)program_.combined_params_buf; } else { self_alloc = true; - data = ReadFileToBuff(program_.para_path); + origin_data = ReadFileToBuff(program_.para_path); } - PADDLE_MOBILE_ENFORCE(data != nullptr, "data == nullptr"); + PADDLE_MOBILE_ENFORCE(origin_data != nullptr, "data == nullptr"); + char *data = origin_data; for (const auto &block : to_predict_program_->Blocks()) { for (const auto &var_desc : block->Vars()) { auto var = program_.scope->Var(var_desc->Name()); @@ -202,7 +204,7 @@ void Executor::InitCombineMemory() { } } if (self_alloc) { - delete [] data; + delete [] origin_data; } LOG(kLOG_INFO) << "init combine memory finish"; }