mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-03-31 17:50:26 +08:00
Resource leak, coverity 1264410
This commit is contained in:
parent
59f8cf19f1
commit
64e69f26f3
@ -18,13 +18,13 @@ static DCEprojection* projectify(CDFnode* field, DCEprojection* container);
|
||||
static int slicematch(NClist* seglist1, NClist* seglist2);
|
||||
|
||||
/* Parse incoming url constraints, if any,
|
||||
to check for syntactic correctness */
|
||||
to check for syntactic correctness */
|
||||
NCerror
|
||||
dapparsedapconstraints(NCDAPCOMMON* dapcomm, char* constraints,
|
||||
DCEconstraint* dceconstraint)
|
||||
{
|
||||
NCerror ncstat = NC_NOERR;
|
||||
char* errmsg;
|
||||
char* errmsg = NULL;
|
||||
|
||||
ASSERT(dceconstraint != NULL);
|
||||
nclistclear(dceconstraint->projections);
|
||||
@ -32,11 +32,12 @@ dapparsedapconstraints(NCDAPCOMMON* dapcomm, char* constraints,
|
||||
|
||||
ncstat = dapceparse(constraints,dceconstraint,&errmsg);
|
||||
if(ncstat) {
|
||||
nclog(NCLOGWARN,"DCE constraint parse failure: %s",errmsg);
|
||||
nullfree(errmsg);
|
||||
nclistclear(dceconstraint->projections);
|
||||
nclistclear(dceconstraint->selections);
|
||||
nclog(NCLOGWARN,"DCE constraint parse failure: %s",errmsg);
|
||||
nclistclear(dceconstraint->projections);
|
||||
nclistclear(dceconstraint->selections);
|
||||
}
|
||||
/* errmsg is freed whether ncstat or not. */
|
||||
nullfree(errmsg);
|
||||
return ncstat;
|
||||
}
|
||||
|
||||
@ -90,7 +91,7 @@ fprintf(stderr,"ncqualifyconstraints.before: %s\n",
|
||||
dumpconstraint(constraint));
|
||||
#endif
|
||||
if(constraint != NULL) {
|
||||
for(i=0;i<nclistlength(constraint->projections);i++) {
|
||||
for(i=0;i<nclistlength(constraint->projections);i++) {
|
||||
DCEprojection* p = (DCEprojection*)nclistget(constraint->projections,i);
|
||||
ncstat = qualifyprojectionnames(p);
|
||||
ncstat = qualifyprojectionsizes(p);
|
||||
@ -257,7 +258,7 @@ matchpartialname(NClist* nodes, NClist* segments, CDFnode** nodep)
|
||||
)
|
||||
continue;
|
||||
nclistpush(namematches,(void*)node);
|
||||
}
|
||||
}
|
||||
if(nclistlength(namematches)==0) {
|
||||
nclog(NCLOGERR,"No match for projection name: %s",lastseg->name);
|
||||
ncstat = NC_EDDS;
|
||||
@ -302,14 +303,14 @@ matchnode->ncfullname,dumpsegments(segments));
|
||||
minpath = nclistlength(matchpath);
|
||||
minnode = candidate;
|
||||
} else if(nclistlength(matchpath) == minpath) {
|
||||
nmin++;
|
||||
nmin++;
|
||||
} else if(nclistlength(matchpath) < minpath) {
|
||||
minpath = nclistlength(matchpath);
|
||||
minnode = candidate;
|
||||
nmin = 1;
|
||||
}
|
||||
} /*for*/
|
||||
if(minnode == NULL || nmin > 1) {
|
||||
if(minnode == NULL || nmin > 1) {
|
||||
nclog(NCLOGERR,"Ambiguous match for projection name: %s",
|
||||
lastseg->name);
|
||||
ncstat = NC_EDDS;
|
||||
@ -461,7 +462,7 @@ dapiswholesegment(DCEsegment* seg)
|
||||
int i,whole;
|
||||
NClist* dimset = NULL;
|
||||
unsigned int rank;
|
||||
|
||||
|
||||
if(seg->rank == 0) return 1;
|
||||
if(!seg->slicesdefined) return 0;
|
||||
if(seg->annotation == NULL) return 0;
|
||||
@ -470,7 +471,7 @@ dapiswholesegment(DCEsegment* seg)
|
||||
whole = 1; /* assume so */
|
||||
for(i=0;i<rank;i++) {
|
||||
CDFnode* dim = (CDFnode*)nclistget(dimset,i);
|
||||
if(!dapiswholeslice(&seg->slices[i],dim)) {whole = 0; break;}
|
||||
if(!dapiswholeslice(&seg->slices[i],dim)) {whole = 0; break;}
|
||||
}
|
||||
return whole;
|
||||
}
|
||||
@ -479,13 +480,13 @@ int
|
||||
dapiswholeprojection(DCEprojection* proj)
|
||||
{
|
||||
int i,whole;
|
||||
|
||||
|
||||
ASSERT((proj->discrim == CES_VAR));
|
||||
|
||||
whole = 1; /* assume so */
|
||||
for(i=0;i<nclistlength(proj->var->segments);i++) {
|
||||
DCEsegment* segment = (DCEsegment*)nclistget(proj->var->segments,i);
|
||||
if(!dapiswholesegment(segment)) {whole = 0; break;}
|
||||
if(!dapiswholesegment(segment)) {whole = 0; break;}
|
||||
}
|
||||
return whole;
|
||||
}
|
||||
@ -550,9 +551,9 @@ fprintf(stderr,"fixprojection: list = %s\n",dumpprojections(list));
|
||||
nclog(NCLOGWARN,"Malformed projection: same variable with different slicing");
|
||||
}
|
||||
/* remove p32 */
|
||||
nclistset(list,j,(void*)NULL);
|
||||
dcefree((DCEnode*)p2);
|
||||
}
|
||||
nclistset(list,j,(void*)NULL);
|
||||
dcefree((DCEnode*)p2);
|
||||
}
|
||||
}
|
||||
|
||||
/* Step 2: remove containers when a field is also present */
|
||||
@ -571,7 +572,7 @@ fprintf(stderr,"fixprojection: list = %s\n",dumpprojections(list));
|
||||
for(k=0;k<nclistlength(tmp);k++) {
|
||||
void* candidate = (void*)nclistget(tmp,k);
|
||||
if(candidate == p1->var->annotation) {
|
||||
nclistset(list,i,(void*)NULL);
|
||||
nclistset(list,i,(void*)NULL);
|
||||
dcefree((DCEnode*)p1);
|
||||
goto next;
|
||||
}
|
||||
@ -607,7 +608,7 @@ next: continue;
|
||||
/* Convert field node to a proper constraint */
|
||||
DCEprojection* proj = projectify(field,container);
|
||||
nclistpush(list,(void*)proj);
|
||||
}
|
||||
}
|
||||
/* reclaim the container */
|
||||
dcefree((DCEnode*)container);
|
||||
}
|
||||
@ -617,8 +618,8 @@ next: continue;
|
||||
for(i=nclistlength(list)-1;i>=0;i--) {
|
||||
DCEprojection* target = (DCEprojection*)nclistget(list,i);
|
||||
if(target == NULL)
|
||||
nclistremove(list,i);
|
||||
}
|
||||
nclistremove(list,i);
|
||||
}
|
||||
|
||||
done:
|
||||
#ifdef DEBUG
|
||||
@ -693,7 +694,7 @@ dapvar2projection(CDFnode* var, DCEprojection** projectionp)
|
||||
DCEprojection* projection = NULL;
|
||||
int dimindex;
|
||||
|
||||
/* Collect the nodes needed to construct the projection segments */
|
||||
/* Collect the nodes needed to construct the projection segments */
|
||||
collectnodepath(var,path,!WITHDATASET);
|
||||
|
||||
segments = nclistnew();
|
||||
@ -724,7 +725,7 @@ dapvar2projection(CDFnode* var, DCEprojection** projectionp)
|
||||
dimindex += localrank;
|
||||
nclistpush(segments,(void*)segment);
|
||||
}
|
||||
|
||||
|
||||
projection = (DCEprojection*)dcecreate(CES_PROJECT);
|
||||
projection->discrim = CES_VAR;
|
||||
projection->var = (DCEvar*)dcecreate(CES_VAR);
|
||||
@ -740,7 +741,7 @@ fprintf(stderr,"dapvar2projection: projection=%s\n",
|
||||
if(ncstat) dcefree((DCEnode*)projection);
|
||||
else if(projectionp) *projectionp = projection;
|
||||
return ncstat;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Given a set of projections and a projection
|
||||
@ -773,7 +774,7 @@ fprintf(stderr,"restrictprojection.before: constraints=|%s| vara=|%s|\n",
|
||||
}
|
||||
if(result == NULL) {
|
||||
result = (DCEprojection*)dceclone((DCEnode*)var); /* use only the var projection */
|
||||
goto done;
|
||||
goto done;
|
||||
}
|
||||
result = (DCEprojection*)dceclone((DCEnode*)result); /* so we can modify */
|
||||
|
||||
@ -784,7 +785,7 @@ fprintf(stderr,"restrictprojection.choice: base=|%s| add=|%s|\n",
|
||||
/* We need to merge the projection from the projection list
|
||||
with the var projection
|
||||
*/
|
||||
ncstat = dcemergeprojections(result,var); /* result will be modified */
|
||||
ncstat = dcemergeprojections(result,var); /* result will be modified */
|
||||
|
||||
done:
|
||||
if(resultp) *resultp = result;
|
||||
@ -859,11 +860,11 @@ dapcomputeprojectedvars(NCDAPCOMMON* dapcomm, DCEconstraint* constraint)
|
||||
CDFnode* node;
|
||||
DCEprojection* proj = (DCEprojection*)nclistget(constraint->projections,i);
|
||||
if(proj->discrim == CES_FCN) continue; /* ignore these */
|
||||
node = (CDFnode*)proj->var->annotation;
|
||||
node = (CDFnode*)proj->var->annotation;
|
||||
if(!nclistcontains(vars,(void*)node)) {
|
||||
nclistpush(vars,(void*)node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
return ncstat;
|
||||
|
Loading…
x
Reference in New Issue
Block a user