struct IOWrapper *
InitDeviceWrapper(const char *path, DeviceInfo_t *devp)
{
- struct DeviceWrapperContext ctx = { 0 };
+ struct DeviceWrapperContext ctx = { .fd = -1 };
struct DeviceWrapperContext *retctx = NULL;
IOWrapper_t *retval = NULL;
struct stat sb;
goto done;
}
- ctx.pathname = strdup(rawname);
-
ctx.fd = open(rawname, O_RDWR);
if (ctx.fd == -1) {
warn("Cannot open device %s for reading and writing", rawname);
retval->cleanup = &noClean;
done:
+ if (!retval) {
+ free(ctx.pathname);
+ free(retctx);
+ if (ctx.fd >= 0)
+ close(ctx.fd);
+ }
+
return retval;
}