Skip to content
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

Memory leak on SendSoap ONVIF library #154

Merged
merged 3 commits into from
Jan 16, 2025
Merged

Conversation

cedricve
Copy link
Member

@cedricve cedricve commented Jan 16, 2025

Description

Pull Request: Memory Leak on SendSoap ONVIF Library

Motivation and Improvement

This pull request addresses a critical memory leak issue in the SendSoap function of the ONVIF library. Memory leaks can lead to increased memory usage over time, which can degrade the performance and reliability of the application. By fixing these leaks, we ensure that the system remains stable and efficient over long periods of operation.

Summary of Changes

  1. Update ONVIF Library:

    • Updated the ONVIF library dependency from version v0.0.16 to v0.0.17 in go.mod and go.sum files. This update includes important bug fixes and improvements, particularly addressing memory management issues.
  2. Ensure Response Body Closure:

    • Added or relocated resp.Body.Close() calls immediately after reading the response body to ensure that the response body is always closed, preventing potential memory leaks.
    • Modified multiple functions such as ConnectToOnvifDevice, GetTokenFromProfile, GetPTZConfigurationsFromDevice, GetPosition, GetPresetsFromDevice, GoToPresetFromDevice, CreatePullPointSubscription, UnsubscribePullPoint, GetEventMessages, GetDigitalInputs, GetRelayOutputs, and TriggerRelayOutput to ensure proper resource cleanup.

Why It Improves the Project

  • Enhanced Stability: By ensuring that response bodies are properly closed, we prevent memory leaks that could lead to crashes or degraded performance.
  • Improved Resource Management: Properly managing resources like network connections and memory helps maintain optimal performance and reliability.
  • Code Quality: Updating to the latest version of the ONVIF library ensures that we benefit from the latest fixes and improvements, which contributes to the overall code quality and maintainability of the project.

These changes are critical for ensuring the long-term health and performance of the application, particularly in environments where the ONVIF functionality is heavily utilized.

@cedricve cedricve merged commit 28b2137 into master Jan 16, 2025
9 checks passed
@cedricve cedricve deleted the fix/memory-leak-onvif branch January 16, 2025 20:55
@cedricve cedricve restored the fix/memory-leak-onvif branch January 19, 2025 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant