mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-25 23:44:35 +00:00
Fix file access race condition.
This commit is contained in:
parent
312713b83c
commit
5037742ab0
@ -3908,17 +3908,14 @@ void Profiler::HandleSymbolCodeQuery( uint64_t symbol, uint32_t size )
|
|||||||
void Profiler::HandleSourceCodeQuery( char* data, char* image, uint32_t id )
|
void Profiler::HandleSourceCodeQuery( char* data, char* image, uint32_t id )
|
||||||
{
|
{
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
struct stat st;
|
|
||||||
if( stat( data, &st ) == 0 && (uint64_t)st.st_mtime < m_exectime )
|
|
||||||
{
|
|
||||||
if( st.st_size < ( TargetFrameSize - 16 ) )
|
|
||||||
{
|
|
||||||
FILE* f = fopen( data, "rb" );
|
FILE* f = fopen( data, "rb" );
|
||||||
if( f )
|
if( f )
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
if( fstat( fileno( f ), &st ) == 0 && (uint64_t)st.st_mtime < m_exectime && st.st_size < ( TargetFrameSize - 16 ) )
|
||||||
{
|
{
|
||||||
auto ptr = (char*)tracy_malloc_fast( st.st_size );
|
auto ptr = (char*)tracy_malloc_fast( st.st_size );
|
||||||
auto rd = fread( ptr, 1, st.st_size, f );
|
auto rd = fread( ptr, 1, st.st_size, f );
|
||||||
fclose( f );
|
|
||||||
if( rd == (size_t)st.st_size )
|
if( rd == (size_t)st.st_size )
|
||||||
{
|
{
|
||||||
TracyLfqPrepare( QueueType::SourceCodeMetadata );
|
TracyLfqPrepare( QueueType::SourceCodeMetadata );
|
||||||
@ -3933,7 +3930,7 @@ void Profiler::HandleSourceCodeQuery( char* data, char* image, uint32_t id )
|
|||||||
tracy_free_fast( ptr );
|
tracy_free_fast( ptr );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
fclose( f );
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TRACY_DEBUGINFOD
|
#ifdef TRACY_DEBUGINFOD
|
||||||
|
Loading…
Reference in New Issue
Block a user