Merged latest changes from cmake development branch.

Addressed a number of memory-related problems
reported by Coverity.
This commit is contained in:
Ward Fisher 2013-04-02 22:09:31 +00:00
parent 405f8bf827
commit 4a274b9870
11 changed files with 66 additions and 52 deletions

View File

@ -643,6 +643,7 @@ CHECK_INCLUDE_FILE("fcntl.h" HAVE_FCNTL_H)
CHECK_INCLUDE_FILE("inttypes.h" HAVE_INTTYPES_H)
CHECK_INCLUDE_FILE("pstdint.h" HAVE_PSTDINT_H)
CHECK_INCLUDE_FILE("endian.h" HAVE_ENDIAN_H)
CHECK_INCLUDE_FILE("BaseTsd.h" HAVE_BASETSD_H)
# Type checks
CHECK_TYPE_SIZE("double" SIZEOF_DOUBLE)
@ -654,10 +655,13 @@ CHECK_TYPE_SIZE("off_t" SIZEOF_OFF_T)
CHECK_TYPE_SIZE("off64_t" SIZEOF_OFF64_T)
CHECK_TYPE_SIZE("short" SIZEOF_SHORT)
CHECK_TYPE_SIZE("size_t" SIZEOF_SIZE_T)
CHECK_TYPE_SIZE("ssize_t" SIZEOF_SSIZE_T)
CHECK_TYPE_SIZE("uchar" SIZEOF_UCHAR)
CHECK_TYPE_SIZE("int64_t" SIZEOF_INT64_T)
CHECK_TYPE_SIZE("uint64_t" SIZEOF_UINT64_T)
SET(HAVE_SSIZE_T SIZEOF_SSIZE_T CACHE STRING "")
# Check for various functions.
CHECK_FUNCTION_EXISTS(fsync HAVE_FSYNC)
CHECK_FUNCTION_EXISTS(strlcat HAVE_STRLCAT)
@ -700,9 +704,9 @@ IF(NOT WIN32)
ENDIF()
# Create config.h file
configure_file("${netCDF_SOURCE_DIR}/cmake_config.h.in"
configure_file("${netCDF_SOURCE_DIR}/config.h.in.cmake"
"${netCDF_BINARY_DIR}/config.h")
configure_file("${netCDF_SOURCE_DIR}/cmake_nc-config.in"
configure_file("${netCDF_SOURCE_DIR}/nc-config.in.cmake"
"${netCDF_SOURCE_DIR}/nc-config")
FILE(COPY "${netCDF_SOURCE_DIR}/nc-config"
DESTINATION "${netCDF_BINARY_DIR}"

View File

@ -10,8 +10,8 @@ ACLOCAL_AMFLAGS = -I m4
# These files get added to the distribution.
EXTRA_DIST = README COPYRIGHT RELEASE_NOTES INSTALL INSTALL.cmake test_prog.c \
lib_flags.am cmake CMakeLists.txt COMPILE_CMake.txt cmake_config.h.in \
cmake_nc-config.in cmake_uninstall.cmake.in netcdf-config-version.cmake.in \
lib_flags.am cmake CMakeLists.txt COMPILE_CMake.txt config.h.in.cmake \
config.h.in.cmake cmake_uninstall.cmake.in netcdf-config-version.cmake.in \
netcdf-config.cmake.in FixBundle.cmake.in
# Doxygen doesn't build nicely in vpath builds.

View File

@ -20,6 +20,14 @@
#define lseek _lseek
#endif
#ifdef _WIN32
#ifndef strcasecmp
#define strcasecmp _stricmp
#define snprintf _snprintf
#endif
#endif
#define strdup _strdup
#define fdopen _fdopen
#define write _write
@ -27,13 +35,6 @@
#define strtoll _strtoi64
#endif
#if defined(_WIN32)
#ifndef strcasecmp
#define strcasecmp _stricmp
#define snprintf _snprintf
#endif
#endif
/* Cache Size, other variables for HDF5 */
@ -184,7 +185,9 @@
/* Define to 1 if you have the <malloc.h> header file. */
#cmakedefine HAVE_MALLOC_H @HAVE_MALLOC_H@
#if !defined(__APPLE__)
/* Define to 1 if you have the BaseTsd.h header file. */
#cmakedefine HAVE_BASETSD_H @HAVE_BASETSD_H@
/* The size of `double` as computed by sizeof. */
#cmakedefine SIZEOF_DOUBLE @SIZEOF_DOUBLE@
/* The size of `float` as computed by sizeof. */
@ -202,22 +205,13 @@
#cmakedefine SIZEOF_SHORT @SIZEOF_SHORT@
/* The size of `size_t` as computed by sizeof. */
#cmakedefine SIZEOF_SIZE_T @SIZEOF_SIZE_T@
/* The size of `ssize_t` as computed by sizeof. */
#cmakedefine SIZEOF_SSIZE_T @SIZEOF_SSIZE_T@
/* The size of `uchar` as computed by sizeof. */
#cmakedefine SIZEOF_UCHAR @SIZEOF_UCHAR@
#else
#define SIZEOF_SHORT 2
#define SIZEOF_INT 4
#if defined(__LP64__) && __LP64__
#define SIZEOF_LONG 8
#define SIZEOF_SIZE_T 8
#else
#define SIZEOF_LONG 4
#define SIZEOF_SIZE_T 4
#endif
#define SIZEOF_FLOAT 4
#define SIZEOF_DOUBLE 8
#define SIZEOF_OFF_T 8
#endif
#cmakedefine TEMP_LARGE "@TEMP_LARGE@"

View File

@ -22,6 +22,17 @@ defined.
extern char* strdup(const char*);
#endif
#if HAVE_BASETSD_H
#include <BaseTsd.h>
#endif
//#ifndef SIZEOF_SSIZE_T
//#undef ssize_t
//#define ssize_t int
//#endif
/* handle null arguments */
#ifndef nulldup
#ifdef HAVE_STRDUP

View File

@ -45,7 +45,7 @@ typedef enum CdTimeUnit {
CdSecond = 8
} CdTimeUnit;
typedef enum cdUnit {
typedef enum cdUnitTime {
cdBadUnit = CdBadTimeUnit,
cdMinute = CdMinute,
cdHour = CdHour,

View File

@ -304,7 +304,7 @@ fprintf(stderr,"conflict: %s[%lu] %s[%lu]\n",
char sindex[64];
snprintf(sindex,sizeof(sindex),"_%d",dim->dim.index1);
dim->ncbasename = (char*)malloc(strlen(sindex)+strlen(legalname)+1);
if(dim->ncbasename == NULL) return NC_ENOMEM;
if(dim->ncbasename == NULL) {nullfree(legalname); return NC_ENOMEM;}
strcpy(dim->ncbasename,legalname);
strcat(dim->ncbasename,sindex);
nullfree(legalname);

View File

@ -1743,20 +1743,8 @@ read_dataset(NC_GRP_INFO_T *grp, const char *obj_name)
if(max_dims) free(max_dims);
return NC_NOERR;
exit:
if (access_pid && H5Pclose(access_pid) < 0)
BAIL2(retval);
#ifdef EXTRA_TESTS
num_plists--;
#endif
if (datasetid && H5Dclose(datasetid) < 0)
BAIL2(retval);
if (spaceid && H5Sclose(spaceid) <0)
BAIL2(retval);
#ifdef EXTRA_TESTS
num_spaces--;
#endif
exit:
if(dims) free(dims);
if(max_dims) free(max_dims);

View File

@ -497,8 +497,11 @@ nc4_find_dim_len(NC_GRP_INFO_T *grp, int dimid, size_t **len)
/* Find dimensions of this var. */
if ((retval = find_var_shape_grp(grp, var->varid, &ndims,
dimids, dimlen)))
dimids, dimlen))) {
free(dimids);
free(dimlen);
return retval;
}
/* Check for any dimension that matches dimid. If found, check
* if its length is longer than *lenp. */
@ -908,6 +911,10 @@ nc4_var_list_del(NC_VAR_INFO_T **list, NC_VAR_INFO_T *var)
NC_ATT_INFO_T *a, *att;
int ret;
if(var == NULL) {
return NC_NOERR;
}
/* First delete all the attributes attached to this var. */
att = var->att;
while (att)
@ -919,16 +926,20 @@ nc4_var_list_del(NC_VAR_INFO_T **list, NC_VAR_INFO_T *var)
}
/* Free some things that may be allocated. */
if (var->chunksizes)
free(var->chunksizes);
if (var->chunksizes)
{free(var->chunksizes);var->chunksizes = NULL;}
if (var->hdf5_name)
free(var->hdf5_name);
{free(var->hdf5_name); var->hdf5_name = NULL;}
if (var->name)
free(var->name);
{free(var->name); var->name = NULL;}
if (var->dimids)
free(var->dimids);
{free(var->dimids); var->dimids = NULL;}
if (var->dim)
free(var->dim);
{free(var->dim); var->dim = NULL;}
/* Remove the var from the linked list. */
if(*list == var)
@ -954,6 +965,7 @@ nc4_var_list_del(NC_VAR_INFO_T **list, NC_VAR_INFO_T *var)
}
}
free(var->fill_value);
var->fill_value = NULL;
}
/* For atomic types we have allocated space for type information. */
@ -971,10 +983,13 @@ nc4_var_list_del(NC_VAR_INFO_T **list, NC_VAR_INFO_T *var)
return NC_EHDFERR;
/* Free the name. */
if (var->type_info->name)
if (var->type_info->name) {
free(var->type_info->name);
var->type_info->name = NULL;
}
free(var->type_info);
var->type_info = NULL;
}
/* Delete any HDF5 dimscale objid information. */
@ -987,6 +1002,7 @@ nc4_var_list_del(NC_VAR_INFO_T **list, NC_VAR_INFO_T *var)
/* Delete the var. */
free(var);
var = NULL;
return NC_NOERR;
}

View File

@ -878,6 +878,7 @@ copy_vars(int igrp, int ogrp)
continue;
NC_CHECK(copy_var(igrp, varid, ogrp));
}
free(vlist);
return stat;
}

View File

@ -1168,7 +1168,7 @@ makespecial(int tag, Symbol* vsym, Symbol* tsym, void* data, int isconst)
Symbol* attr = NULL;
Datalist* list;
Constant* con;
Specialdata* special;
Specialdata* special = (Specialdata*)malloc(sizeof(Specialdata));
Constant iconst;
int tf = 0;
char* sdata = NULL;