mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-02-17 16:50:18 +08:00
Addressed a memory leak issue identified by static analysis.
This commit is contained in:
parent
cad531a487
commit
a641a8834d
@ -109,7 +109,7 @@ dcelex(YYSTYPE* lvalp, DCEparsestate* state)
|
||||
isnumber = 1; /* maybe */
|
||||
}
|
||||
/* A number followed by an id char is assumed to just be
|
||||
a funny id */
|
||||
a funny id */
|
||||
if(isnumber && (*p == '\0' || strchr(wordcharsn,*p) == NULL)) {
|
||||
token = SCAN_NUMBERCONST;
|
||||
} else {
|
||||
@ -191,9 +191,22 @@ void
|
||||
dcelexinit(char* input, DCElexstate** lexstatep)
|
||||
{
|
||||
DCElexstate* lexstate = (DCElexstate*)malloc(sizeof(DCElexstate));
|
||||
if(lexstatep) *lexstatep = lexstate;
|
||||
|
||||
/* If lexstatep is NULL,
|
||||
we want to free lexstate and
|
||||
return to avoid a memory leak. */
|
||||
if(lexstatep) {
|
||||
*lexstatep = lexstate;
|
||||
} else {
|
||||
if(lexstate) free(lexstate);
|
||||
return;
|
||||
}
|
||||
|
||||
if(lexstate == NULL) return;
|
||||
memset((void*)lexstate,0,sizeof(DCElexstate));
|
||||
|
||||
|
||||
|
||||
#ifdef URLDECODE
|
||||
lexstate->input = ncuridecode(input);
|
||||
#else
|
||||
@ -221,4 +234,3 @@ dcelexcleanup(DCElexstate** lexstatep)
|
||||
free(lexstate);
|
||||
*lexstatep = NULL;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user