Bug: client_cli.c may free() a string literal for server_host #166

Closed
opened 2026-07-29 18:36:31 +02:00 by TapTap · 0 comments
Owner

Description

client_cli.c declares char* server_host = "127.0.0.1"; at file scope. When the user provides --server-host, the code does free(server_host); and assigns a newly allocated string. If server_host is never reassigned (the common case), no free() is called, so the literal is safe. However, the pattern is fragile: any future change that frees the default value would invoke undefined behavior.

Location

  • src/client/client_cli.c:14server_host initialized to a string literal.
  • src/client/client_cli.c:160free(server_host); before reassignment.

Suggested fix

  1. Initialize server_host with str_dup("127.0.0.1") so it is always heap-allocated.
  2. Ensure server_host is freed during cleanup.

Severity

Low

Category

bug, quality


This issue was automatically generated by the issue-creator agent.

## Description `client_cli.c` declares `char* server_host = "127.0.0.1";` at file scope. When the user provides `--server-host`, the code does `free(server_host);` and assigns a newly allocated string. If `server_host` is never reassigned (the common case), no `free()` is called, so the literal is safe. However, the pattern is fragile: any future change that frees the default value would invoke undefined behavior. ## Location - `src/client/client_cli.c:14` — `server_host` initialized to a string literal. - `src/client/client_cli.c:160` — `free(server_host);` before reassignment. ## Suggested fix 1. Initialize `server_host` with `str_dup("127.0.0.1")` so it is always heap-allocated. 2. Ensure `server_host` is freed during cleanup. ## Severity Low ## Category bug, quality --- _This issue was automatically generated by the issue-creator agent._
TapTap added the bugqualityneeds-triage labels 2026-07-29 18:36:31 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: TapTap/FastSync#166