Fix some data races (issue #1218)

This commit is contained in:
Abs62 2019-11-19 19:20:44 +03:00
parent 1cef1a8733
commit d54e0ca9fd
5 changed files with 10 additions and 2 deletions

1
gls.cc
View file

@ -1535,6 +1535,7 @@ void GlsResourceRequest::run()
memcpy( &data.front(), bytes.constData(), bytes.size() );
}
Mutex::Lock _( dataMutex );
hasAnyData = true;
}
catch( std::exception &ex )

4
mdx.cc
View file

@ -697,13 +697,13 @@ void MdxArticleRequest::run()
"</i></i></i></i></i></i></i></i>"
"</a></a></a></a></a></a></a></a>";
articleText += "<div class=\"mdict\">" + articleBody + cleaner + "</div>\n";
hasAnyData = true;
}
if ( hasAnyData )
if ( !articleText.empty() )
{
Mutex::Lock _( dataMutex );
data.insert( data.end(), articleText.begin(), articleText.end() );
hasAnyData = true;
}
finish();

View file

@ -1624,6 +1624,8 @@ void SlobResourceRequest::run()
QString css = QString::fromUtf8( resource.data(), resource.size() );
dict.isolateCSS( css, ".slobdict" );
QByteArray bytes = css.toUtf8();
Mutex::Lock _( dataMutex );
data.resize( bytes.size() );
memcpy( &data.front(), bytes.constData(), bytes.size() );
}
@ -1666,6 +1668,7 @@ void SlobResourceRequest::run()
memcpy( &data.front(), resource.data(), data.size() );
}
Mutex::Lock _( dataMutex );
hasAnyData = true;
}
catch( std::exception &ex )

View file

@ -1905,6 +1905,7 @@ void StardictResourceRequest::run()
memcpy( &data.front(), bytes.constData(), bytes.size() );
}
Mutex::Lock _( dataMutex );
hasAnyData = true;
}
catch( std::exception &ex )

3
zim.cc
View file

@ -1446,6 +1446,8 @@ void ZimResourceRequest::run()
QString css = QString::fromUtf8( resource.data(), resource.size() );
dict.isolateCSS( css, ".zimdict" );
QByteArray bytes = css.toUtf8();
Mutex::Lock _( dataMutex );
data.resize( bytes.size() );
memcpy( &data.front(), bytes.constData(), bytes.size() );
}
@ -1488,6 +1490,7 @@ void ZimResourceRequest::run()
memcpy( &data.front(), resource.data(), data.size() );
}
Mutex::Lock _( dataMutex );
hasAnyData = true;
}
catch( std::exception &ex )