modules+util: fix actual (potential) memory leaks

This commit is contained in:
Tamino Bauknecht
2023-10-20 22:41:53 +02:00
parent a0b63d6b1e
commit ae748b2644
6 changed files with 39 additions and 19 deletions

View File

@ -2,6 +2,8 @@
#include <spdlog/spdlog.h>
#include "util/scope_guard.hpp"
waybar::modules::Custom::Custom(const std::string& name, const std::string& id,
const Json::Value& config)
: ALabel(config, "custom-" + name, id, "{}"),
@ -57,6 +59,11 @@ void waybar::modules::Custom::continuousWorker() {
}
thread_ = [this, cmd] {
char* buff = nullptr;
waybar::util::scope_guard buff_deleter([buff]() {
if (buff) {
free(buff);
}
});
size_t len = 0;
if (getline(&buff, &len, fp_) == -1) {
int exit_code = 1;
@ -90,7 +97,6 @@ void waybar::modules::Custom::continuousWorker() {
output_ = {0, output};
dp.emit();
}
free(buff);
};
}