Addressed a few high impact issues identified by Coverity

This commit is contained in:
Ward Fisher 2013-03-14 22:38:31 +00:00
parent e80c20a3f5
commit 3f9c05c71b
6 changed files with 18 additions and 9 deletions

View File

@ -25,7 +25,7 @@ dapmerge3(NCDAPCOMMON* nccomm, CDFnode* ddsroot, OCddsnode dasroot)
NClist* allnodes;
OClink conn;
char* ocname = NULL;
char** values = NULL;
conn = nccomm->oc.conn;
if(ddsroot == NULL || dasroot == NULL) return NC_NOERR;
@ -44,7 +44,7 @@ dapmerge3(NCDAPCOMMON* nccomm, CDFnode* ddsroot, OCddsnode dasroot)
OCCHECK(oc_dds_attr_count(conn,ocnode,&attrcount));
for(j=0;j<attrcount;j++) {
size_t nvalues;
char** values = NULL;
NCattribute* att = NULL;
if(ocname != NULL) {
@ -103,11 +103,13 @@ fprintf(stderr,"%s.Unlimited_Dimension=%s\n",node->ocname,nccomm->cdf.recorddimn
if(values) {
oc_reclaim_strings(nvalues,values);
free(values);
values = NULL;
}
}
}
done:
if(values != NULL) free(values);
if(ocname != NULL) free(ocname);
if(ocstat != OC_NOERR) ncstat = ocerrtoncerr(ocstat);
return THROW(ncstat);
@ -120,7 +122,7 @@ buildattribute(char* name, nc_type ptype,
{
int i;
NCerror ncstat = NC_NOERR;
NCattribute* att;
NCattribute* att = NULL;
att = (NCattribute*)calloc(1,sizeof(NCattribute));
MEMCHECK(att,NC_ENOMEM);
@ -132,6 +134,8 @@ buildattribute(char* name, nc_type ptype,
nclistpush(att->values,(void*)nulldup(values[i]));
if(attp) *attp = att;
else
free(att);
return THROW(ncstat);
}

View File

@ -115,9 +115,10 @@ NC4_inq_typeid(int ncid, const char *name, nc_type *typeidp)
/* Normalize name. */
if (!(norm_name = (char*)malloc(strlen(name) + 1)))
return NC_ENOMEM;
if ((retval = nc4_normalize_name(name, norm_name)))
return retval;
if ((retval = nc4_normalize_name(name, norm_name))) {
free(norm_name);
return retval;
}
/* Is the type in this group? If not, search parents. */
for (grp2 = grp; grp2; grp2 = grp2->parent)
for (type = grp2->type; type; type = type->next)

View File

@ -32,12 +32,13 @@ bin_constant(Generator* generator, Constant* con, Bytebuffer* buf,...)
}
switch (con->nctype) {
case NC_OPAQUE: {
unsigned char* bytes;
unsigned char* bytes = NULL;
size_t len;
/* Assume the opaque string has been normalized */
bytes=makebytestring(con->value.opaquev.stringv,&len);
bbAppendn(buf,(void*)bytes,len);
} break;
free(bytes);
} break;
case NC_CHAR:
bbAppendn(buf,&con->value.charv,sizeof(con->value.charv));
break;

View File

@ -606,6 +606,7 @@ convertstringtochars(Constant* str)
con.nctype = NC_CHAR;
con.lineno = str->lineno;
con.value.charv = s[i];
con.filled = 0;
dlappend(dl,&con);
}
return dl;

View File

@ -309,6 +309,8 @@ daplexinit(char* input, DAPlexstate** lexstatep)
lexstate->yytext = ocbytesnew();
lexstate->reclaim = oclistnew();
dapsetwordchars(lexstate,0); /* Assume DDS */
if(!lexstatep)
free(lexstate);
}
void

View File

@ -365,7 +365,7 @@ createtempfile1(char* tmppath, char** tmpnamep)
int fd = 0;
char* tmpname = NULL;
size_t tmpsize = strlen(tmppath)+strlen("dataddsXXXXXX") + 1;
tmpname = (char*)malloc(tmpsize);
tmpname = (char*)alloca(tmpsize);
if(tmpname == NULL) return -1;
if(!occopycat(tmpname,tmpsize,1,tmppath))
return OC_EOVERRUN;