Skip to content

TSan: CurrentTimeString uses non-reentrant localtime() from every logging thread #132

Closed

Description

@zackees

Found by the TSan launch pass (meta issue linked as parent). Upstream OBS code, unchanged in this fork.

Race

WARNING: ThreadSanitizer: data race
  Write of size 8 by thread T49 'threaded-ml':
    #0 localtime
    #1 CurrentTimeString()   frontend/obs-main.cpp:94
    #2 LogStringChunk        frontend/obs-main.cpp:124
    #3 do_log                frontend/obs-main.cpp:233
    #4 blogva                libobs/util/base.c:116
  Previous write of size 8 by thread T8 'audio-io: audio':
    #0 localtime  ... same stack
  Location is global '_tmbuf' (libc)

Cause

CurrentTimeString() uses localtime(), which returns a pointer to a static buffer shared by every thread. blog() is called from the audio, video, capture and UI threads at the same time, so two log lines can swap or corrupt each other's timestamps.

Fix

Use localtime_r(&now, &tstruct) (localtime_s on Windows), the same as the rest of libobs's platform code.

Activity

  1. added
    bug
    on Oct 10, 2026
  2. zackees commented on Oct 13, 2026

    @zackees
    MemberAuthor

    Claiming: #132. Plan: localtime_r / localtime_s in CurrentTimeString(). One PR.

  3. added
    claimed
    on Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugclaimed

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions