6 Commits

Author SHA1 Message Date
utox39
3b3c29e22d Merge pull request #8 from utox39/fix-linux-gpu/fix-memory-leak
Fix linux gpu/fix memory leak
2025-07-29 17:08:10 +02:00
utox39
a866952f86 build: bump version to 0.7.4 2025-07-29 17:06:40 +02:00
utox39
5d7bdd8041 fix(linux-gpu): fix memory leak 2025-07-29 17:05:30 +02:00
utox39
635dfe00db Merge pull request #7 from utox39/fix-linux-gpu/fix-double-free
Fix linux gpu/fix double free
2025-07-28 23:40:56 +02:00
utox39
064e8e9597 build: bump version to 0.7.3 2025-07-28 23:39:40 +02:00
utox39
785915d833 fix(linux-gpu): fix double free 2025-07-28 23:38:36 +02:00
2 changed files with 12 additions and 5 deletions

View File

@@ -10,7 +10,7 @@
// This is a [Semantic Version](https://semver.org/). // This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication. // In a future version of Zig it will be used for package deduplication.
.version = "0.7.2", .version = "0.7.4",
// Together with name, this represents a globally unique package // Together with name, this represents a globally unique package
// identifier. This field is generated by the Zig toolchain when the // identifier. This field is generated by the Zig toolchain when the

View File

@@ -144,9 +144,16 @@ pub fn getGpuInfo(allocator: std.mem.Allocator) !std.ArrayList(GpuInfo) {
); );
const gpu_name = try allocator.dupe(u8, std.mem.span(name)); const gpu_name = try allocator.dupe(u8, std.mem.span(name));
defer allocator.free(gpu_name);
const parsed_gpu_name = try parseGpuName(allocator, gpu_name); const maybe_parsed_gpu_name = try parseGpuName(allocator, gpu_name);
var parsed_gpu_name: []u8 = undefined;
if (maybe_parsed_gpu_name != null) {
allocator.free(gpu_name);
parsed_gpu_name = maybe_parsed_gpu_name.?;
} else {
parsed_gpu_name = gpu_name;
}
try gpu_info_list.append(GpuInfo{ try gpu_info_list.append(GpuInfo{
.gpu_name = parsed_gpu_name, .gpu_name = parsed_gpu_name,
@@ -167,7 +174,7 @@ pub fn getGpuInfo(allocator: std.mem.Allocator) !std.ArrayList(GpuInfo) {
return gpu_info_list; return gpu_info_list;
} }
fn parseGpuName(allocator: std.mem.Allocator, name: []u8) ![]u8 { fn parseGpuName(allocator: std.mem.Allocator, name: []u8) !?[]u8 {
// NOTE: for references: https://github.com/pciutils/pciutils/blob/master/pci.ids // NOTE: for references: https://github.com/pciutils/pciutils/blob/master/pci.ids
if (std.mem.startsWith(u8, name, "Advanced Micro Devices, Inc. [AMD/ATI]")) { if (std.mem.startsWith(u8, name, "Advanced Micro Devices, Inc. [AMD/ATI]")) {
@@ -190,7 +197,7 @@ fn parseGpuName(allocator: std.mem.Allocator, name: []u8) ![]u8 {
return parsed_gpu_name; return parsed_gpu_name;
} }
return name; return null;
} }
pub fn getRamInfo(allocator: std.mem.Allocator) !RamInfo { pub fn getRamInfo(allocator: std.mem.Allocator) !RamInfo {