Fixed a potential memory leak identified by static analysis.
* buffer of metadata information, i.e. the linked list of NC
* structs.
*
- * @author Ed Hartnett
+ * @author Ed Hartnett, Dennis Heimbigner, Ward Fisher
*/
#include "config.h"
#include "nc4internal.h"
@@ -935,12 +935,12 @@ nc4_check_dup_name(NC_GRP_INFO_T *grp, char *name)
*
* @return ::NC_NOERR No error.
* @return ::NC_ENOMEM Out of memory.
- * @author Ed Hartnett
+ * @author Ed Hartnett, Ward Fisher
*/
int
nc4_type_new(NC_GRP_INFO_T *grp, size_t size, const char *name, int assignedid, NC_TYPE_INFO_T **type)
{
- NC_TYPE_INFO_T *new_type;
+ NC_TYPE_INFO_T *new_type = NULL;
/* Allocate memory for the type */
if (!(new_type = calloc(1, sizeof(NC_TYPE_INFO_T))))
@@ -950,8 +950,10 @@ nc4_type_new(NC_GRP_INFO_T *grp, size_t size, const char *name, int assignedid,
/* Remember info about this type. */
new_type->hdr.id = assignedid;
new_type->size = size;
- if (!(new_type->hdr.name = strdup(name)))
+ if (!(new_type->hdr.name = strdup(name))) {
+ free(new_type);
return NC_ENOMEM;
+ }
new_type->hdr.hashkey = NC_hashmapkey(name,strlen(name));
