diff --git a/src/vio/csync_vio.c b/src/vio/csync_vio.c index 21f7bb92f..d13c9db6a 100644 --- a/src/vio/csync_vio.c +++ b/src/vio/csync_vio.c @@ -24,6 +24,7 @@ #define _GNU_SOURCE #endif +#include #include #include /* dlopen(), dlclose(), dlsym() ... */ @@ -160,23 +161,28 @@ csync_vio_handle_t *csync_vio_creat(CSYNC *ctx, const char *uri, mode_t mode) { return h; } -int csync_vio_close(CSYNC *ctx, csync_vio_handle_t *handle) { +int csync_vio_close(CSYNC *ctx, csync_vio_handle_t *fhandle) { int rc = -1; + if (fhandle == NULL) { + errno = EBADF; + return -1; + } + switch(ctx->replica) { case REMOTE_REPLCIA: - rc = ctx->module.method->close(handle->method_handle); + rc = ctx->module.method->close(fhandle->method_handle); break; case LOCAL_REPLICA: - rc = csync_vio_local_close(handle->method_handle); + rc = csync_vio_local_close(fhandle->method_handle); break; default: break; } /* handle->method_handle is free'd by the above close */ - SAFE_FREE(handle->uri); - SAFE_FREE(handle); + SAFE_FREE(fhandle->uri); + SAFE_FREE(fhandle); return rc; } @@ -184,6 +190,11 @@ int csync_vio_close(CSYNC *ctx, csync_vio_handle_t *handle) { ssize_t csync_vio_read(CSYNC *ctx, csync_vio_handle_t *fhandle, void *buf, size_t count) { ssize_t rs = 0; + if (fhandle == NULL) { + errno = EBADF; + return -1; + } + switch(ctx->replica) { case REMOTE_REPLCIA: rs = ctx->module.method->read(fhandle->method_handle, buf, count); @@ -201,6 +212,11 @@ ssize_t csync_vio_read(CSYNC *ctx, csync_vio_handle_t *fhandle, void *buf, size_ ssize_t csync_vio_write(CSYNC *ctx, csync_vio_handle_t *fhandle, const void *buf, size_t count) { ssize_t rs = 0; + if (fhandle == NULL) { + errno = EBADF; + return -1; + } + switch(ctx->replica) { case REMOTE_REPLCIA: rs = ctx->module.method->write(fhandle->method_handle, buf, count); @@ -258,6 +274,11 @@ csync_vio_handle_t *csync_vio_opendir(CSYNC *ctx, const char *name) { int csync_vio_closedir(CSYNC *ctx, csync_vio_handle_t *dhandle) { int rc = -1; + if (dhandle == NULL) { + errno = EBADF; + return -1; + } + switch(ctx->replica) { case REMOTE_REPLCIA: rc = ctx->module.method->closedir(dhandle->method_handle);