Fix memory use after free: buffer need to be attached to the module. (#76350)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/76350

fix memory issue

Test Plan:
User reported ASAN errors when running `//xplat/langtech/mobile:giga5_bin`

Verified with the user that rebasing to this diff it is gone.

Reviewed By: pavithranrao

Differential Revision: D35911894

fbshipit-source-id: 41eb88fe1501d1bb7dd9ce3d36c224c3300a41e8
(cherry picked from commit 3a13aae20f698bc5bcc4d5cb686bb36d433a2f03)
This commit is contained in:
Han Qi
2022-04-25 19:46:53 -07:00
committed by PyTorch MergeBot
parent b26df43f15
commit 6d0f2be31c

View File

@ -555,6 +555,7 @@ mobile::Module _load_for_mobile(
mobile::serialization::GetMutableModule(data.get());
mobile::Module m = initialize_mobile_module(flatbuffer_module);
parseExtraFiles(flatbuffer_module, extra_files);
m.set_delete_memory(data);
return m;
}
#else
@ -604,6 +605,7 @@ mobile::Module _load_for_mobile(
mobile::serialization::GetMutableModule(data.get());
mobile::Module m = initialize_mobile_module(flatbuffer_module);
parseExtraFiles(flatbuffer_module, extra_files);
m.set_delete_memory(data);
return m;
}
#else