Fix memory leak on error, fix power ppd being required for falcond to launch.
Some checks failed
PikaOS Package Build & Release (amd64-v3) / build (push) Failing after 17s

This commit is contained in:
ferreo 2025-02-10 18:11:06 +00:00
parent 75d6d24d2f
commit 54a7b7dc73
5 changed files with 39 additions and 21 deletions

View File

@ -1 +1 @@
1
2

View File

@ -1,3 +1,9 @@
falcond (1.1.0-101pika1) pika; urgency=low
* Fix memory leak on error, fix power ppd being required for falcond to launch.
-- ferreo <ferreo@pika-os.com> Sun, 12 Jan 2025 13:48:00 +0300
falcond (1.0.9-101pika2) pika; urgency=low
* Config parsing fixes

View File

@ -13,7 +13,7 @@ pub const PowerProfiles = struct {
original_profile: ?[]const u8,
has_performance: bool,
pub fn init(allocator: std.mem.Allocator, config: Config) !*PowerProfiles {
pub fn init(allocator: std.mem.Allocator, config: Config) !?*PowerProfiles {
var self = try allocator.create(PowerProfiles);
errdefer allocator.destroy(self);
@ -37,7 +37,11 @@ pub const PowerProfiles = struct {
.has_performance = false,
};
const profiles = try self.getAvailableProfiles(allocator);
const profiles = self.getAvailableProfiles(allocator) catch |err| {
std.log.err("Failed to get power profiles: {}, power profiles will be disabled", .{err});
allocator.destroy(self);
return null;
};
defer {
for (profiles) |profile| {
allocator.free(profile);

View File

@ -15,7 +15,7 @@ pub const Daemon = struct {
profile_manager: ProfileManager,
oneshot: bool,
known_pids: ?std.AutoHashMap(u32, *const Profile),
power_profiles: *PowerProfiles,
power_profiles: ?*PowerProfiles,
performance_mode: bool,
last_profiles_check: i128,
last_config_check: i128,
@ -30,13 +30,17 @@ pub const Daemon = struct {
const system_conf_path_owned = try allocator.dupe(u8, system_conf_path);
errdefer allocator.free(system_conf_path_owned);
const config = try Config.load(allocator, config_path, system_conf_path);
const power_profiles = try PowerProfiles.init(allocator, config);
errdefer power_profiles.deinit();
var config = try Config.load(allocator, config_path, system_conf_path);
errdefer config.deinit();
const performance_mode = power_profiles.isPerformanceAvailable();
if (performance_mode) {
std.log.info("Performance profile available - power profile management enabled", .{});
const power_profiles = try PowerProfiles.init(allocator, config);
var performance_mode = false;
if (power_profiles) |pp| {
performance_mode = pp.isPerformanceAvailable();
if (performance_mode) {
std.log.info("Performance profile available - power profile management enabled", .{});
}
}
var profile_manager = ProfileManager.init(allocator, power_profiles, config);
@ -66,7 +70,9 @@ pub const Daemon = struct {
pub fn deinit(self: *Self) void {
scx_scheds.deinit();
self.profile_manager.deinit();
self.power_profiles.deinit();
if (self.power_profiles) |pp| {
pp.*.deinit();
}
if (self.known_pids) |*map| {
map.deinit();
}
@ -86,7 +92,9 @@ pub const Daemon = struct {
}
self.profile_manager.deinit();
self.power_profiles.deinit();
if (self.power_profiles) |pp| {
pp.*.deinit();
}
self.config.deinit();
const config = try Config.load(self.allocator, self.config_path, self.system_conf_path);
@ -96,7 +104,7 @@ pub const Daemon = struct {
self.config = config;
self.power_profiles = power_profiles;
self.performance_mode = self.power_profiles.isPerformanceAvailable();
self.performance_mode = if (power_profiles) |pp| pp.isPerformanceAvailable() else false;
self.profile_manager = profile_manager;
}

View File

@ -14,10 +14,10 @@ pub const ProfileManager = struct {
proton_profile: ?*const Profile,
active_profile: ?*const Profile = null,
queued_profiles: std.ArrayList(*const Profile),
power_profiles: *PowerProfiles,
power_profiles: ?*PowerProfiles,
config: Config,
pub fn init(allocator: std.mem.Allocator, power_profiles: *PowerProfiles, config: Config) ProfileManager {
pub fn init(allocator: std.mem.Allocator, power_profiles: ?*PowerProfiles, config: Config) ProfileManager {
return .{
.allocator = allocator,
.profiles = std.ArrayList(Profile).init(allocator),
@ -47,9 +47,9 @@ pub const ProfileManager = struct {
std.log.info("Activating profile: {s}", .{profile.name});
self.active_profile = profile;
if (profile.performance_mode and self.power_profiles.isPerformanceAvailable()) {
if (profile.performance_mode and self.power_profiles != null and self.power_profiles.?.isPerformanceAvailable()) {
std.log.info("Enabling performance mode for profile: {s}", .{profile.name});
self.power_profiles.enablePerformanceMode();
self.power_profiles.?.enablePerformanceMode();
}
const effective_mode = if (self.config.vcache_mode != .none)
@ -80,9 +80,9 @@ pub const ProfileManager = struct {
if (active == profile) {
std.log.info("Deactivating profile: {s}", .{profile.name});
if (profile.performance_mode and self.power_profiles.isPerformanceAvailable()) {
if (profile.performance_mode and self.power_profiles != null and self.power_profiles.?.isPerformanceAvailable()) {
std.log.info("Disabling performance mode for profile: {s}", .{profile.name});
self.power_profiles.disablePerformanceMode();
self.power_profiles.?.disablePerformanceMode();
}
vcache_setting.applyVCacheMode(.none);
@ -102,9 +102,9 @@ pub const ProfileManager = struct {
if (active == profile) {
std.log.info("Unloading profile: {s}", .{profile.name});
if (profile.performance_mode and self.power_profiles.isPerformanceAvailable()) {
if (profile.performance_mode and self.power_profiles != null and self.power_profiles.?.isPerformanceAvailable()) {
std.log.info("Disabling performance mode for profile: {s}", .{profile.name});
self.power_profiles.disablePerformanceMode();
self.power_profiles.?.disablePerformanceMode();
}
vcache_setting.applyVCacheMode(.none);