Scanner stores pointers to exclude/include patterns without ownership #64

Closed
opened 2026-07-20 17:14:08 +02:00 by TapTap · 0 comments
Owner

Description

In src/shared/scanner.c lines 27-31, directory_scanner_create() stores pointers to the caller's pattern arrays:

scanner->exclude_patterns = exclude_patterns;
scanner->include_patterns = include_patterns;

These are pointers into the Config's pattern arrays. If the Config is freed before the scanner is destroyed, these pointers become dangling. Currently in the codebase, the scanner is always used within the lifetime of the config, but this is an implicit contract that could be violated by future refactoring.

Location

src/shared/scanner.c:27-31

Suggested Fix

Either:

  1. Deep-copy the pattern arrays into the scanner
  2. Add a documentation comment making the lifetime requirement explicit
  3. Change the scanner to take a Config* and reference patterns through it

Severity

Low

Category

Quality

## Description In `src/shared/scanner.c` lines 27-31, `directory_scanner_create()` stores pointers to the caller's pattern arrays: ```c scanner->exclude_patterns = exclude_patterns; scanner->include_patterns = include_patterns; ``` These are pointers into the `Config`'s pattern arrays. If the `Config` is freed before the scanner is destroyed, these pointers become dangling. Currently in the codebase, the scanner is always used within the lifetime of the config, but this is an implicit contract that could be violated by future refactoring. ## Location `src/shared/scanner.c:27-31` ## Suggested Fix Either: 1. Deep-copy the pattern arrays into the scanner 2. Add a documentation comment making the lifetime requirement explicit 3. Change the scanner to take a `Config*` and reference patterns through it ## Severity Low ## Category Quality
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: TapTap/FastSync#64