Skip to content

Commit 7429ff0

Browse files
committed
Fix #884: FORMATing dates can deadlock under Unix
Don't acquire FB_STRLOCK in fb_StrFormat, because it can call fb_DrvIntlGetMonthName and fb_DrvIntlGetWeekdayName which under Unix acquire FB_LOCK. This reverses part of r3440/8b2da10
1 parent e669d91 commit 7429ff0

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Version 1.06.0
6161
- Fixed inline asm procedure name mangling bug (missing underscore prefix) with -gen gcc -asm intel on dos/win32
6262
- #878: Fix fbc-64bit hangs on 'Case True' + 'Case False' inside 'Select Case As const'
6363
- Fix SELECT CASE AS CONST to allow both signed & unsigned case range values
64+
- #884: FORMATing dates can deadlock under Unix
6465

6566

6667
Version 1.05.0

src/rtlib/fb.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,14 @@
112112
FBCALL void fb_StrUnlock( void );
113113
FBCALL void fb_GraphicsLock ( void );
114114
FBCALL void fb_GraphicsUnlock( void );
115+
/* NOTE: if both locks are acquired, FB_LOCK() must be called before
116+
FB_STRLOCK() in order to avoid deadlocking */
115117
#define FB_LOCK() fb_Lock()
116118
#define FB_UNLOCK() fb_Unlock()
117119
#define FB_STRLOCK() fb_StrLock()
118120
#define FB_STRUNLOCK() fb_StrUnlock()
121+
/* FIXME: consistent locking order of FB_LOCK and FB_GRAPHICS_LOCK is
122+
required. See bug #885 */
119123
#define FB_GRAPHICS_LOCK() fb_GraphicsLock()
120124
#define FB_GRAPHICS_UNLOCK() fb_GraphicsUnlock()
121125
#else

src/rtlib/str_format.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ FBSTRING *fb_hBuildDouble
142142
LenTotal = LenSign + LenFix + LenDecPoint + LenFrac;
143143

144144
/* alloc temp string */
145-
dst = fb_hStrAllocTemp_NoLock( NULL, LenTotal );
145+
dst = fb_hStrAllocTemp( NULL, LenTotal );
146146
if( dst != NULL )
147147
{
148148
if( LenSign!=0 ) {
@@ -1154,6 +1154,7 @@ FBCALL FBSTRING *fb_hStrFormat
11541154

11551155
fb_ErrorSetNum( FB_RTERROR_OK );
11561156

1157+
/* Lock to prevent inconsistent results if fb_I18nSet() called? */
11571158
FB_LOCK();
11581159
pszIntlResult = fb_IntlGet( eFIL_NumDecimalPoint, FALSE );
11591160
chDecimalPoint = (( pszIntlResult==NULL ) ? '.' : *pszIntlResult );
@@ -1170,8 +1171,6 @@ FBCALL FBSTRING *fb_hStrFormat
11701171
if( chThousandsSep==0 )
11711172
chThousandsSep = ',';
11721173

1173-
FB_STRLOCK();
1174-
11751174
if( mask == NULL || mask_length==0 )
11761175
{
11771176
dst = fb_hBuildDouble( value, chDecimalPoint, 0 );
@@ -1187,7 +1186,7 @@ FBCALL FBSTRING *fb_hStrFormat
11871186
chThousandsSep, chDecimalPoint,
11881187
chDateSep, chTimeSep ) )
11891188
{
1190-
dst = fb_hStrAllocTemp_NoLock( NULL, info.length_min + info.length_opt );
1189+
dst = fb_hStrAllocTemp( NULL, info.length_min + info.length_opt );
11911190
if( dst == NULL )
11921191
{
11931192
fb_ErrorSetNum( FB_RTERROR_OUTOFMEM );
@@ -1205,8 +1204,6 @@ FBCALL FBSTRING *fb_hStrFormat
12051204
}
12061205
}
12071206

1208-
FB_STRUNLOCK();
1209-
12101207
return dst;
12111208
}
12121209

0 commit comments

Comments
 (0)