Skip to content

Fix memory safety and error handling issues #52

@RAprogramm

Description

@RAprogramm

Description

This PR addresses critical memory safety and error handling issues identified in the codebase.

Issues Fixed

1. Memory Leaks via Box::leak()

Files affected:

  • cli/src/dispatch.rs:17
  • cli/src/parsers.rs:16, 19, 29, 62, 98-102

Problem: Each command execution leaks memory permanently via Box::leak(). These leaks accumulate over time and cannot be reclaimed.

Solution: Replace Box::leak() with proper lifetime management using Cow or owned String types.

2. Missing Error Handling (unwrap/expect)

Files affected:

  • cli/src/keyword.rs:7, 12, 27, 30
  • cli/src/dispatch.rs:118
  • hyde-ipc-lib/src/service.rs:62, 74, 89

Problem: Using unwrap() and expect() causes panics instead of returning errors, making the application crash on failures.

Solution: Replace all unwrap()/expect() calls with proper Result propagation.

3. Unsafe Send/Sync Implementations

Files affected:

  • hyprland-lib/src/unsafe_impl.rs

Problem: Unsafe trait implementations without safety documentation or verification can lead to undefined behavior and data races.

Solution: Add safety documentation and verify thread safety guarantees, or remove unsafe implementations if not required.

4. Abrupt Process Termination

Files affected:

  • cli/src/listen.rs:180
  • hyde-ipc-lib/src/service.rs:93

Problem: std::process::exit() terminates the process immediately without running destructors or cleanup code, potentially leaving resources in inconsistent state.

Solution: Replace with proper error propagation and graceful shutdown.

Testing

All changes will maintain existing functionality while improving safety and reliability.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions