fixed memleak and uninitilized value
This commit is contained in:
parent
e2f04637f2
commit
e893852bc1
|
@ -0,0 +1,16 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// from: https://www.gingerbill.org/article/2015/08/19/defer-in-cpp/
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
struct privDefer {
|
||||||
|
std::function<void()> f;
|
||||||
|
privDefer(std::function<void()> f) : f(f) {}
|
||||||
|
~privDefer() { f(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
#define DEFER_1(x, y) x##y
|
||||||
|
#define DEFER_2(x, y) DEFER_1(x, y)
|
||||||
|
#define DEFER_3(x) DEFER_2(x, __COUNTER__)
|
||||||
|
#define defer(code) auto DEFER_3(_defer_) = privDefer([&](){code;})
|
|
@ -47,7 +47,7 @@ private:
|
||||||
|
|
||||||
Config::PositionConfig* conf;
|
Config::PositionConfig* conf;
|
||||||
DataDragon* dd = nullptr;
|
DataDragon* dd = nullptr;
|
||||||
Position position;
|
Position position = Position::INVALID;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SETTINGSTAB_H
|
#endif // SETTINGSTAB_H
|
||||||
|
|
|
@ -60,6 +60,7 @@ HEADERS += \
|
||||||
include/config.h \
|
include/config.h \
|
||||||
include/datadragon.h \
|
include/datadragon.h \
|
||||||
include/datadragonimagecache.h \
|
include/datadragonimagecache.h \
|
||||||
|
include/defer.h \
|
||||||
include/files.h \
|
include/files.h \
|
||||||
include/json.h \
|
include/json.h \
|
||||||
include/lolautoaccept.h \
|
include/lolautoaccept.h \
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
#include <Log.h>
|
#include <Log.h>
|
||||||
|
|
||||||
|
#include "defer.h"
|
||||||
|
|
||||||
static bool endsWith(const std::string& all, const std::string& end) {
|
static bool endsWith(const std::string& all, const std::string& end) {
|
||||||
return all.rfind(end) == all.size() - end.size();
|
return all.rfind(end) == all.size() - end.size();
|
||||||
}
|
}
|
||||||
|
@ -42,6 +44,8 @@ std::shared_ptr<ClientAccess> ClientAccess::find(bool uselockfile) {
|
||||||
DIR* procdir = opendir("/proc");
|
DIR* procdir = opendir("/proc");
|
||||||
if(!procdir) return nullptr;
|
if(!procdir) return nullptr;
|
||||||
|
|
||||||
|
defer( closedir(procdir) );
|
||||||
|
|
||||||
dirent* entry = nullptr;
|
dirent* entry = nullptr;
|
||||||
while ((entry = readdir(procdir)) != NULL) {
|
while ((entry = readdir(procdir)) != NULL) {
|
||||||
if (entry->d_type != DT_DIR) continue;
|
if (entry->d_type != DT_DIR) continue;
|
||||||
|
@ -82,8 +86,6 @@ std::shared_ptr<ClientAccess> ClientAccess::find(bool uselockfile) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(procdir);
|
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue