Skip to content

Commit 4fa515c

Browse files
committed
dat1FreeLoc: Ensure locator is non-NULL before using it.
1 parent 0be8050 commit 4fa515c

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

dat1FreeLoc.c

+14-12
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,22 @@
9999
HDSLoc *
100100
dat1FreeLoc( HDSLoc * locator, int * status ) {
101101

102-
/* Sanity check */
103-
if( *status == SAI__OK ){
104-
if( locator->prev || locator->next || locator->hdsFile ){
105-
*status = DAT__FATAL;
106-
emsRep( " ", "Attempt to free HDS locator that is still registered.",
107-
status );
102+
/* Do nothing if no locator was supplied */
103+
if (locator) {
104+
105+
/* Sanity check */
106+
if( *status == SAI__OK ){
107+
if( locator->prev || locator->next || locator->hdsFile ){
108+
*status = DAT__FATAL;
109+
emsRep( " ", "Attempt to free HDS locator that is still registered.",
110+
status );
111+
}
108112
}
109-
}
110113

111-
/* Always attempt to free the memory even if status
112-
is bad */
113-
if (locator) {
114-
memset( locator, 0, sizeof( *locator ));
115-
MEM_FREE(locator);
114+
/* Always attempt to free the memory even if status is bad */
115+
memset( locator, 0, sizeof( *locator ));
116+
MEM_FREE(locator);
116117
}
118+
117119
return NULL;
118120
}

0 commit comments

Comments
 (0)