diff --git a/linux/device.c b/linux/device.c index dc1804e..a8c630b 100644 --- a/linux/device.c +++ b/linux/device.c @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -33,9 +34,19 @@ void* DeviceOpen(const char* device_path) { DeviceContext* ctx; + char *real_device_path = realpath(device_path, NULL); + if(real_device_path != NULL) + { + device_path = real_device_path; + } + ctx = malloc(sizeof(DeviceContext)); - if(!ctx) return NULL; + if(!ctx) + { + free(real_device_path); + return NULL; + } memset(ctx, 0, sizeof(DeviceContext)); @@ -45,12 +56,15 @@ void* DeviceOpen(const char* device_path) if(ctx->fd <= 0) { + free(real_device_path); free(ctx); return NULL; } strncpy(ctx->device_path, device_path, 4096); + free(real_device_path); + return ctx; }