-
Notifications
You must be signed in to change notification settings - Fork 1
hotfix: memory leaks and long-running crashes #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements comprehensive resource monitoring and leak detection for hyprlax, addressing stability issues in long-running sessions. The changes include a built-in resource monitor, improved GPU synchronization for hyprlock compatibility, proper cleanup of GIF textures and Wayland resources, thread-safe layer operations, and signal-safe shutdown handling.
- Added resource monitoring subsystem with FD/memory leak detection and IPC integration
- Fixed GPU sync blocking with hyprlock by replacing glFinish() with glFenceSync()
- Implemented proper cleanup for GIF textures, Wayland surfaces, and monitor resources
- Added thread-safe layer list access with mutex protection across all operations
- Improved error handling for Wayland display errors and epoll failures
Reviewed Changes
Copilot reviewed 31 out of 32 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/core/resource_monitor.c | New resource monitoring implementation tracking FDs, memory, and GPU resources |
| src/include/resource_monitor.h | Resource monitor API definitions and data structures |
| tests/test_resource_monitor.c | Comprehensive unit tests for resource monitoring functionality |
| src/renderer/gles2.c | GPU sync fix using glFenceSync instead of glFinish for hyprlock compatibility |
| src/platform/wayland.c | Enhanced error handling and resource cleanup for Wayland connections |
| src/hyprlax_main.c | GIF texture cleanup fix and layer mutex initialization |
| src/core/event_loop.c | Signal-safe shutdown and resource monitoring integration |
| src/ipc.c | Added resource_status command and timeout handling |
| src/core/time_utils.c | 64-bit timestamp utilities to prevent overflow |
| scripts/monitor_resources.sh | Resource monitoring script for production use |
| scripts/analyze_resources.py | Leak detection analysis tool |
| docs/resource_monitoring.md | Complete documentation for resource monitoring system |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Description
Critical hotfix addressing memory leaks and long-running stability issues in hyprlax. This PR fixes several severe resource management bugs causing crashes during extended runtime, monitor hotplug scenarios, and GIF layer operations.
Type of Change
Related Issue
Fixes crashes during extended runtime and monitor sleep/wake cycles
Changes Made
Phase 1: Critical Memory Leak Fixes
1. Output Info Memory Leak (CRITICAL) -
src/platform/wayland.c:251-278registry_global_remove()to properly freeoutput_info_tstructures (~80 bytes each)2. Frame Callback Cleanup (CRITICAL) -
src/core/monitor.c:75-913. Layer Image Path Management (HIGH) -
src/hyprlax.c:585-592strdup()allocation insync_ipc_layers()Phase 2: Resource Management Improvements
4. EGL Surface Cleanup on Failure (CRITICAL) -
src/platform/wayland.c:715-7475. Monitor Failed Flag (NEW) - Multiple files
failedflag tomonitor_instance_tstructuresrc/core/monitor.h:79,src/core/monitor.c:61,src/platform/wayland.c:743,747,src/hyprlax_main.c:1194,1202,src/core/render_core.c:59-626. Complete Monitor Destruction (ENHANCED) -
src/core/monitor.c:81-131monitor_instance_destroy()with complete resource cleanupgles2_destroy_monitor_surface()insrc/renderer/gles2.c:1064-10717. GIF Texture Cleanup (CRITICAL) -
src/hyprlax_main.c:1263-1313Phase 3: Thread Safety & Signal Handling
8. Layer List Thread Safety (HIGH) - Multiple files
layer_mutextohyprlax_context_tfor thread-safe layer operationssrc/hyprlax_main.c: add, remove, workspace change, update operationssrc/ipc.c: IPC command handlers (add, remove, modify, list, clear)src/core/event_loop.c: animation checking9. Signal-Safe Shutdown (HIGH) -
src/main.c,src/core/event_loop.cctx->runningflag withvolatile sig_atomic_t g_shutdown_requestedepoll_wait()from infinite timeout to 5-second watchdog10. Enhanced Error Handling (IMPROVED)
Monitoring & Testing Infrastructure
11. Resource Monitoring Tools (NEW)
scripts/monitor_resources.sh: Real-time resource usage trackingscripts/analyze_resources.py: Statistical analysis of resource logstests/stress/test_overnight.sh: 24-hour stress test with hotplug simulationtests/test_resource_monitor.c: Unit tests for resource monitoringsrc/core/resource_monitor.c,src/core/time_utils.c12. Documentation (NEW)
MEMORY_LEAK_FIXES.md: Detailed analysis of Phase 1 critical fixesRESOURCE_MANAGEMENT_FIXES.md: Comprehensive Phase 2 resource management documentation.gitignoreto exclude test artifacts and resource logsTesting
make testpasses all tests (requires runtime environment)make memcheckshows no memory leaks (requires Valgrind + runtime)Recommended Manual Testing
valgrind --leak-check=full --track-origins=yes ./hyprlaxChecklist
Code Quality
Testing
tests/stress/test_overnight.sh)tests/test_resource_monitor.c)Documentation
MEMORY_LEAK_FIXES.md,RESOURCE_MANAGEMENT_FIXES.md)Focus
Impact Analysis
Memory Savings
Stability Improvements
Files Modified (16 files, +787 lines, -31 lines)
Core Changes:
src/core/event_loop.c- Signal handling, thread safety, epoll error handlingsrc/core/monitor.c,src/core/monitor.h- Frame callback cleanup, failed flag, complete destructionsrc/hyprlax_main.c- Layer mutex, GIF cleanup, thread-safe operationssrc/main.c- Signal-safe shutdown flagsrc/platform/wayland.c- Output info cleanup, EGL surface error handlingsrc/renderer/gles2.c- Monitor surface destroy helpersrc/include/renderer.h,src/include/hyprlax.h- Function declarations, context updatessrc/ipc.c- Thread-safe IPC handlersNew Files:
src/core/resource_monitor.c,src/include/resource_monitor.h- Resource monitoring systemsrc/core/time_utils.c,src/include/time_utils.h- Time utility functionsscripts/monitor_resources.sh- Resource monitoring scriptscripts/analyze_resources.py- Resource analysis tooltests/stress/test_overnight.sh- Overnight stress testtests/test_resource_monitor.c- Resource monitor unit testsBuild & Config:
Makefile- Added new source files and test targets.gitignore- Exclude test artifactsAdditional Notes
This is a critical stability hotfix that addresses multiple severe bugs discovered during extended testing. The fixes are surgical and focused on resource management without changing functional behavior. All changes maintain backward compatibility and follow existing code patterns.
The addition of resource monitoring tools and stress tests ensures these issues can be detected early in future development.
Priority: CRITICAL - Fixes production crashes and memory leaks
Risk: LOW - Surgical fixes to resource cleanup, no functional changes
Testing: MEDIUM - Requires extended runtime testing to fully validate