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

Fix sqlops memory leak in sql_avp_load / sql_avp_delete / sql_avp_store (for 3.5 and master) #3576

Merged
merged 1 commit into from
Feb 26, 2025

Conversation

nikbyte
Copy link
Member

@nikbyte nikbyte commented Feb 9, 2025

Summary
This pull request fixes a memory leak in the sqlops module (function fixup_sql_avp) where a dynamically allocated string (sp->u.s.s) was not released in certain error paths or after normal fixup usage.

Details
When parsing script parameters for sql_avp_load() / sql_avp_delete() / sql_avp_store(), if the first parameter was a plain string (not prefixed by '$'), the code allocated memory for sp->u.s.s. However, it never got properly freed:

  1. In the error path (goto err_free:), only sp was freed, leaving sp->u.s.s allocated.
  2. In the success path, there was no custom fixup_free_* function to release sp->u.s.s.

Repeated calls thus caused incremental memory leaks.

Solution

  1. Introduced a new free function fixup_free_avp_source() that properly frees both sp->u.s.s (if allocated) and the sp structure.
  2. Updated the module to use this free function instead of the standard fixup_free_pkg().

By doing so, all allocated memory is correctly released, eliminating the leak.

Compatibility
No breaking changes or behavioral differences other than fixing the memory usage issue. No impacts on SIP interoperability or script compatibility.

@nikbyte nikbyte added the bug label Feb 9, 2025
@nikbyte nikbyte force-pushed the memfix_sqlops branch 2 times, most recently from 88808b6 to 68c01be Compare February 10, 2025 13:36
@nikbyte nikbyte closed this Feb 10, 2025
@nikbyte nikbyte reopened this Feb 10, 2025
@bogdan-iancu bogdan-iancu self-assigned this Feb 26, 2025
@bogdan-iancu
Copy link
Member

Thank you @nikbyte , I will backport this to 3.5 also

@bogdan-iancu bogdan-iancu merged commit 523ed18 into OpenSIPS:master Feb 26, 2025
99 of 102 checks passed
bogdan-iancu added a commit that referenced this pull request Feb 26, 2025
Fix sqlops memory leak in sql_avp_load / sql_avp_delete / sql_avp_store (for 3.5 and master)

(cherry picked from commit 523ed18)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants