From 743f9093176f6aa98980a028e59fd583cff4c5ca Mon Sep 17 00:00:00 2001 From: blitter Date: Sun, 4 Dec 2022 14:54:51 -0800 Subject: [PATCH] Pass a temporary DeviceContext to GetDeviceType. --- linux/list_devices.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/linux/list_devices.c b/linux/list_devices.c index 37a7da9..dd06c5a 100644 --- a/linux/list_devices.c +++ b/linux/list_devices.c @@ -49,6 +49,8 @@ DeviceInfoList* ListDevices() udev = udev_new(); has_udev = udev != 0; +#else + DeviceContext tmp_ctx; #endif dir = opendir(PATH_SYS_DEVBLOCK); @@ -137,11 +139,10 @@ DeviceInfoList* ListDevices() #else // Use sysfs if(!has_udev && !strstr(dirent->d_name, "loop")) { - tmp_string = malloc(1024); - memset((void*)tmp_string, 0, 1024); - snprintf((char*)tmp_string, 1024, "/dev/%s", dirent->d_name); + memset((void*)tmp_ctx.device_path, 0, 4096); + snprintf((char*)tmp_ctx.device_path, 4096, "/dev/%s", dirent->d_name); - switch(GetDeviceType(tmp_string)) + switch(GetDeviceType(&tmp_ctx)) { case AARUREMOTE_DEVICE_TYPE_ATA: strncpy(list_next->this.bus, "ATA", 256); break; case AARUREMOTE_DEVICE_TYPE_ATAPI: strncpy(list_next->this.bus, "ATAPI", 256); break; @@ -149,6 +150,7 @@ DeviceInfoList* ListDevices() case AARUREMOTE_DEVICE_TYPE_SECURE_DIGITAL: strncpy(list_next->this.bus, "MMC/SD", 256); break; case AARUREMOTE_DEVICE_TYPE_NVME: strncpy(list_next->this.bus, "NVMe", 256); break; case AARUREMOTE_DEVICE_TYPE_SCSI: + tmp_string = malloc(1024); memset((void*)tmp_string, 0, 1024); snprintf((char*)tmp_string, 1024, "%s/%s/device", PATH_SYS_DEVBLOCK, dirent->d_name); line_str = malloc(1024); @@ -208,11 +210,10 @@ DeviceInfoList* ListDevices() free(line_str); } + free((void*)tmp_string); break; default: memset(&list_next->this.bus, 0, 256); break; } - - free((void*)tmp_string); } #endif