Skip to content

Commit f81e0af

Browse files
committed
fix: tform: potential crash due to race when MODMAX/MODMIN
A worker could free a dollar variable's data, while another worker is trying to read it. Lock the dollar variable before working out its RHS in case the RHS depends on the dollar variable that is being assigned.
1 parent 9b0d11c commit f81e0af

1 file changed

Lines changed: 4 additions & 12 deletions

File tree

sources/dollar.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -394,14 +394,11 @@ NoChangeOne:;
394394
}
395395
/*
396396
Now the real evaluation.
397-
In the case of threads and MODSUM this requires an immediate lock.
398-
Otherwise the lock could be placed later.
397+
We need to lock here before we work out the RHS, in case the RHS itself
398+
depends on the dollar variable.
399399
*/
400400
#ifdef WITHPTHREADS
401-
if ( dtype == MODSUM ) {
402-
/* LOCK(d->pthreadslockwrite); */
403-
LOCK(d->pthreadslockread);
404-
}
401+
LOCK(d->pthreadslockread);
405402
#endif
406403
CleanDollarFactors(d);
407404
/*
@@ -445,12 +442,7 @@ NoChangeOne:;
445442
}
446443
numterms = 0; t = ss; while ( *t ) { numterms++; t += *t; }
447444
}
448-
#ifdef WITHPTHREADS
449-
if ( dtype != MODSUM ) {
450-
/* LOCK(d->pthreadslockwrite); */
451-
LOCK(d->pthreadslockread);
452-
}
453-
#endif
445+
454446
if ( numterms == 0 ) {
455447
/*
456448
the new value evaluates to zero

0 commit comments

Comments
 (0)