[opencv] 148/251: dnn: fix torch importer memory leaks
Nobuhiro Iwamatsu
iwamatsu at moszumanska.debian.org
Sun Aug 27 23:27:37 UTC 2017
This is an automated email from the git hooks/post-receive script.
iwamatsu pushed a commit to annotated tag 3.3.0
in repository opencv.
commit 878a6906cc24589d443de0b8dd980e9fa7838c02
Author: Alexander Alekhin <alexander.alekhin at intel.com>
Date: Tue Jul 25 12:20:55 2017 +0300
dnn: fix torch importer memory leaks
---
modules/dnn/src/torch/torch_importer.cpp | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/modules/dnn/src/torch/torch_importer.cpp b/modules/dnn/src/torch/torch_importer.cpp
index 7c1d4e7..44fcd8c 100644
--- a/modules/dnn/src/torch/torch_importer.cpp
+++ b/modules/dnn/src/torch/torch_importer.cpp
@@ -100,7 +100,7 @@ struct TorchImporter : public ::cv::dnn::Importer
typedef std::map<String, std::pair<int, Mat> > TensorsMap;
Net net;
- THFile *file;
+ cv::Ptr<THFile> file;
std::set<int> readedIndexes;
std::map<int, Mat> storages;
std::map<int, Mat> tensors;
@@ -126,7 +126,7 @@ struct TorchImporter : public ::cv::dnn::Importer
rootModule = curModule = NULL;
moduleCounter = 0;
- file = THDiskFile_new(filename.c_str(), "r", 0);
+ file = cv::Ptr<THFile>(THDiskFile_new(filename.c_str(), "r", 0), THFile_free);
CV_Assert(file && THFile_isOpened(file));
if (isBinary)
@@ -976,18 +976,20 @@ struct TorchImporter : public ::cv::dnn::Importer
{
CV_TRACE_FUNCTION();
- if (rootModule == NULL)
- {
- rootModule = new Module("Sequential");
- curModule = rootModule;
+ CV_Assert(rootModule == NULL);
+ cv::Ptr<Module> rootModule_ = cv::makePtr<Module>("Sequential");
+ rootModule = rootModule_.get();
+ curModule = rootModule;
- THFile_seek(file, 0);
- readObject();
- }
+ THFile_seek(file, 0);
+ readObject();
net = net_;
std::vector<std::pair<int, Module*> > addedModules;
fill(rootModule, addedModules);
+
+ rootModule = NULL;
+ curModule = NULL;
}
};
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/opencv.git
More information about the debian-science-commits
mailing list