Skip to content
Snippets Groups Projects
Commit 06089003 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Fix memory leaks and double frees

parent 1c0fa6bd
No related branches found
No related tags found
No related merge requests found
Pipeline #15335 passed
......@@ -161,7 +161,7 @@ static void run(ftl::Configurable *root) {
ftl::rgbd::Streamer *stream = ftl::create<ftl::rgbd::Streamer>(root, "stream", net);
ftl::rgbd::VirtualSource *virt = ftl::create<ftl::rgbd::VirtualSource>(root, "virtual");
ftl::render::Splatter *splat = ftl::create<ftl::render::Splatter>(root, "renderer", &scene_B);
ftl::rgbd::Group group;
ftl::rgbd::Group *group = new ftl::rgbd::Group;
ftl::ILW *align = ftl::create<ftl::ILW>(root, "merge");
int o = root->value("origin_pose", 0) % sources.size();
......@@ -184,7 +184,7 @@ static void run(ftl::Configurable *root) {
for (size_t i=0; i<sources.size(); i++) {
Source *in = sources[i];
in->setChannel(Channel::Depth);
group.addSource(in);
group->addSource(in);
}
// ---- Recording code -----------------------------------------------------
......@@ -195,7 +195,7 @@ static void run(ftl::Configurable *root) {
ftl::codecs::StreamPacket s = spkt;
// Patch stream ID to match order in group
s.streamID = group.streamID(src);
s.streamID = group->streamID(src);
writer.write(s, pkt);
};
......@@ -212,14 +212,14 @@ static void run(ftl::Configurable *root) {
writer.begin();
// TODO: Write pose+calibration+config packets
auto sources = group.sources();
auto sources = group->sources();
for (int i=0; i<sources.size(); ++i) {
writeSourceProperties(writer, i, sources[i]);
}
group.addRawCallback(std::function(recorder));
group->addRawCallback(std::function(recorder));
} else {
group.removeRawCallback(recorder);
group->removeRawCallback(recorder);
writer.end();
fileout.close();
}
......@@ -228,14 +228,14 @@ static void run(ftl::Configurable *root) {
// -------------------------------------------------------------------------
stream->setLatency(5); // FIXME: This depends on source!?
stream->add(&group);
stream->add(group);
stream->run();
bool busy = false;
group.setLatency(5);
group.setName("ReconGroup");
group.sync([splat,virt,&busy,&slave,&scene_A,&scene_B,&align](ftl::rgbd::FrameSet &fs) -> bool {
group->setLatency(5);
group->setName("ReconGroup");
group->sync([splat,virt,&busy,&slave,&scene_A,&scene_B,&align](ftl::rgbd::FrameSet &fs) -> bool {
//cudaSetDevice(scene->getCUDADevice());
if (slave.isPaused()) return true;
......@@ -284,6 +284,9 @@ static void run(ftl::Configurable *root) {
delete stream;
delete virt;
delete net;
delete group;
ftl::config::cleanup(); // Remove any last configurable objects.
LOG(INFO) << "Done.";
}
......
......@@ -39,7 +39,7 @@ class Configurable {
public:
Configurable();
explicit Configurable(nlohmann::json &config);
virtual ~Configurable() {}
virtual ~Configurable();
/**
* Force the JSON object to have specific properties with a specific type.
......
......@@ -37,6 +37,10 @@ Configurable *configure(int argc, char **argv, const std::string &root);
Configurable *configure(json_t &);
void cleanup();
void removeConfigurable(Configurable *cfg);
/**
* Change a configuration value based upon a URI. Return true if changed,
* false if it was not able to change.
......
......@@ -21,6 +21,10 @@ Configurable::Configurable(nlohmann::json &config) : config_(&config) {
ftl::config::registerConfigurable(this);
}
Configurable::~Configurable() {
ftl::config::removeConfigurable(this);
}
void Configurable::required(const char *f, const std::vector<std::tuple<std::string, std::string, std::string>> &r) {
bool diderror = false;
for (auto i : r) {
......
......@@ -470,6 +470,24 @@ Configurable *ftl::config::configure(ftl::config::json_t &cfg) {
return rootcfg;
}
static bool doing_cleanup = false;
void ftl::config::cleanup() {
doing_cleanup = true;
for (auto f : config_instance) {
delete f.second;
}
config_instance.clear();
}
void ftl::config::removeConfigurable(Configurable *cfg) {
if (doing_cleanup) return;
auto i = config_instance.find(cfg->getID());
if (i != config_instance.end()) {
config_instance.erase(i);
}
}
Configurable *ftl::config::configure(int argc, char **argv, const std::string &root) {
loguru::g_preamble_date = false;
......
......@@ -151,9 +151,9 @@ public:
private:
struct ChannelData {
ftl::cuda::TextureObjectBase tex;
cv::Mat host;
cv::cuda::GpuMat gpu;
ftl::cuda::TextureObjectBase tex;
};
std::array<ChannelData, Channels::kMax> data_;
......
......@@ -59,7 +59,7 @@ Source::Source(ftl::config::json_t &cfg, ftl::net::Universe *net) : Configurable
}
Source::~Source() {
if (impl_) delete impl_;
}
cv::Mat Source::cameraMatrix() const {
......@@ -338,6 +338,7 @@ void Source::setCallback(std::function<void(int64_t, cv::Mat &, cv::Mat &)> cb)
void Source::addRawCallback(const std::function<void(ftl::rgbd::Source*, const ftl::codecs::StreamPacket &spkt, const ftl::codecs::Packet &pkt)> &f) {
UNIQUE_LOCK(mutex_,lk);
LOG(INFO) << "ADD RAW";
rawcallbacks_.push_back(f);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment