Skip to content

Commit

Permalink
Merge pull request #29 from ISISComputingGroup/check_null
Browse files Browse the repository at this point in the history
Check for NULL pointer
  • Loading branch information
Tom-Willemsen authored Jun 27, 2024
2 parents f68d753 + 41b141c commit b0ef31a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions asyn/asynDriver/asynManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,9 @@ static const char *asynStripPath(const char *file)
return file;
}

static void asynInit(void)
static void asynInitOnceImpl(void* arg)
{
int i;

if(pasynBase) return;
pasynBase = callocMustSucceed(1,sizeof(asynBase),"asynInit");
ellInit(&pasynBase->asynPortList);
ellInit(&pasynBase->asynUserFreeList);
Expand All @@ -503,6 +501,13 @@ static void asynInit(void)
pasynBase->autoConnectTimeout = DEFAULT_AUTOCONNECT_TIMEOUT;
}

static epicsThreadOnceId asynInitOnce = EPICS_THREAD_ONCE_INIT;

static void asynInit(void)
{
epicsThreadOnce(&asynInitOnce, asynInitOnceImpl, NULL);
}

static void dpCommonInit(port *pport,device *pdevice,BOOL autoConnect)
{
dpCommon *pdpCommon;
Expand Down Expand Up @@ -530,6 +535,7 @@ static void dpCommonFree(dpCommon *pdpCommon)

static dpCommon *findDpCommon(userPvt *puserPvt)
{
if (!puserPvt) return(0);
port *pport = puserPvt->pport;
device *pdevice = puserPvt->pdevice;

Expand All @@ -540,6 +546,7 @@ static dpCommon *findDpCommon(userPvt *puserPvt)

static tracePvt *findTracePvt(userPvt *puserPvt)
{
if(!pasynBase) asynInit();
dpCommon *pdpCommon = findDpCommon(puserPvt);
if(pdpCommon) return(&pdpCommon->trace);
return(&pasynBase->trace);
Expand Down

0 comments on commit b0ef31a

Please sign in to comment.