From d033f9f6ff4dfec0ed4f78be85239c380a95074b Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Thu, 20 Feb 2014 08:24:55 -0600 Subject: [PATCH] Clean up Coverity warnings from last checkin. --- include/netcdf.h | 3 +++ libdap2/cdf3.c | 20 ++++++++------------ libsrc4/nc4file.c | 9 ++++++--- libsrc4/nc4var.c | 6 ++++++ oc2/ocutil.c | 4 ++++ 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/include/netcdf.h b/include/netcdf.h index 828ff225b..3e0b3494c 100644 --- a/include/netcdf.h +++ b/include/netcdf.h @@ -369,6 +369,9 @@ by the desired type. */ #define NC_EDAPCONSTRAINT (-75) /**< Malformed DAP Constraint*/ #define NC_ETRANSLATION (-76) /**< Untranslatable construct */ +/* Misc. additional errors */ +#define NC_ECANTREMOVE (-77) /**< Can't remove file */ + /* The following was added in support of netcdf-4. Make all netcdf-4 error codes < -100 so that errors can be added to netcdf-3 if needed. */ diff --git a/libdap2/cdf3.c b/libdap2/cdf3.c index 76ff35adb..6b9bc6331 100644 --- a/libdap2/cdf3.c +++ b/libdap2/cdf3.c @@ -659,19 +659,15 @@ static NClist* clonedimset3(NCDAPCOMMON* nccomm, NClist* dimset, CDFnode* var) { NClist* result = NULL; - - - - int i; - if(dimset != NULL) { - for(i=0;iname); LOG((3, "%s: grp->name %s", __func__, grp->name)); + /* Portably initialize user data for later */ + memset(&udata, 0, sizeof(udata)); + /* Open this HDF5 group and retain its grpid. It will remain open * with HDF5 until this file is nc_closed. */ if (!grp->hdf_grpid) @@ -2009,8 +2012,7 @@ nc4_rec_read_metadata(NC_GRP_INFO_T *grp) iter_index = H5_INDEX_NAME; } - /* Portably initialize user data for iteration */ - memset(&udata, 0, sizeof(udata)); + /* Set user data for iteration */ udata.grp = grp; /* Iterate over links in this group, building lists for the types, @@ -2981,7 +2983,8 @@ NC4_abort(int ncid) /* Delete the file, if we should. */ if (delete_file) - remove(path); + if (remove(path) < 0) + return NC_ECANTREMOVE; return retval; } diff --git a/libsrc4/nc4var.c b/libsrc4/nc4var.c index 0813f1803..4cd939ab3 100644 --- a/libsrc4/nc4var.c +++ b/libsrc4/nc4var.c @@ -746,7 +746,10 @@ NC4_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep, return NC_ENOMEM; if (*(char **)var->fill_value) if (!(*(char **)fill_valuep = strdup(*(char **)var->fill_value))) + { + free(fill_valuep); return NC_ENOMEM; + } } else { assert(var->type_info->size); @@ -760,7 +763,10 @@ NC4_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep, if (!(fill_valuep = calloc(1, sizeof(char *)))) return NC_ENOMEM; if ((retval = nc4_get_default_fill_value(var->type_info, (char **)fill_valuep))) + { + free(fill_valuep); return retval; + } } else { diff --git a/oc2/ocutil.c b/oc2/ocutil.c index 8a0010468..ac59e2ab4 100644 --- a/oc2/ocutil.c +++ b/oc2/ocutil.c @@ -725,6 +725,10 @@ ocmktmp(const char* base, char** tmpnamep, int* fdp) # endif } #endif /* !HAVE_MKSTEMP */ + if(fd < 0) { + free(tmpname); + return OC_EOPEN; + } if(tmpnamep) *tmpnamep = tmpname; else free(tmpname); if(fdp) *fdp = fd;