Skip to content

Fix the memory leaks observed by ASan testing#4690

Merged
tanscorpio7 merged 1 commit intobabelfish-for-postgresql:BABEL_5_X_DEVfrom
amazon-aurora:babel-6422
Apr 2, 2026
Merged

Fix the memory leaks observed by ASan testing#4690
tanscorpio7 merged 1 commit intobabelfish-for-postgresql:BABEL_5_X_DEVfrom
amazon-aurora:babel-6422

Conversation

@harshdubey166
Copy link
Copy Markdown
Contributor

@harshdubey166 harshdubey166 commented Apr 1, 2026

Description

This PR fixes the memory leaks observed when testing with ASan.

  1. In the function PrepareRowDescription() , strdup() allocates memory using the system's malloc(), which is completely outside PostgreSQL's memory management. This means the string stored in relMetaDataInfo->partName[1] lives in malloc-heap, not in any PostgreSQL memory context.
    By using pstrdup() , it allocates using palloc() inside the current memory context (MessageContext), so it's properly tracked and will be freed when that context is destroyed.

  2. Similarly in the function rewrite_if_condition(), strdup uses malloc which is invisible to PostgreSQL's memory management while pstrdup allocates in the current memory context, which gets cleaned up automatically.

Issues Resolved

[BABEL-6422]

Authored by : harshdu@amazon.com
Signed-off by : harshdu@amazon.com

Check List

  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is under the terms of the Apache 2.0 and PostgreSQL licenses, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.

For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Harsh Dubey <harshdu@amazon.com>
@tanscorpio7 tanscorpio7 merged commit dab7675 into babelfish-for-postgresql:BABEL_5_X_DEV Apr 2, 2026
47 checks passed
@tanscorpio7 tanscorpio7 deleted the babel-6422 branch April 2, 2026 06:37
harshdubey166 added a commit to amazon-aurora/babelfish_extensions that referenced this pull request Apr 2, 2026
This commit fixes memory leaks observed when testing with ASan

1. In the function TdsSendRowDescription() , strdup() allocates memory using the system's malloc(), which is completely outside PostgreSQL's memory management. This means the string stored in relMetaDataInfo->partName[1] lives in malloc-heap, not in any PostgreSQL memory context.
By using pstrdup() , it allocates using palloc() inside the current memory context (MessageContext), so it's properly tracked and will be freed when that context is destroyed.

2. Similarly in the function rewrite_if_condition(), strdup uses malloc which is invisible to PostgreSQL's memory management while pstrdup allocates in the current memory context, which gets cleaned up automatically.

Task: BABEL-6422

Authored by : harshdu@amazon.com
harshdubey166 added a commit to amazon-aurora/babelfish_extensions that referenced this pull request Apr 2, 2026
This commit fixes memory leaks observed when testing with ASan

1. In the function TdsSendRowDescription() , strdup() allocates memory using the system's malloc(), which is completely outside PostgreSQL's memory management. This means the string stored in relMetaDataInfo->partName[1] lives in malloc-heap, not in any PostgreSQL memory context.
By using pstrdup() , it allocates using palloc() inside the current memory context (MessageContext), so it's properly tracked and will be freed when that context is destroyed.

2. Similarly in the function rewrite_if_condition(), strdup uses malloc which is invisible to PostgreSQL's memory management while pstrdup allocates in the current memory context, which gets cleaned up automatically.

Task: BABEL-6422

Authored by : harshdu@amazon.com
tanscorpio7 pushed a commit that referenced this pull request Apr 2, 2026
This commit fixes memory leaks observed when testing with ASan

1. In the function TdsSendRowDescription() , strdup() allocates memory using the system's malloc(), which is completely outside PostgreSQL's memory management. This means the string stored in relMetaDataInfo->partName[1] lives in malloc-heap, not in any PostgreSQL memory context.
By using pstrdup() , it allocates using palloc() inside the current memory context (MessageContext), so it's properly tracked and will be freed when that context is destroyed.

2. Similarly in the function rewrite_if_condition(), strdup uses malloc which is invisible to PostgreSQL's memory management while pstrdup allocates in the current memory context, which gets cleaned up automatically.

Task: BABEL-6422

Authored by : harshdu@amazon.com
tanscorpio7 pushed a commit that referenced this pull request Apr 2, 2026
This commit fixes memory leaks observed when testing with ASan

1. In the function TdsSendRowDescription() , strdup() allocates memory using the system's malloc(), which is completely outside PostgreSQL's memory management. This means the string stored in relMetaDataInfo->partName[1] lives in malloc-heap, not in any PostgreSQL memory context.
By using pstrdup() , it allocates using palloc() inside the current memory context (MessageContext), so it's properly tracked and will be freed when that context is destroyed.

2. Similarly in the function rewrite_if_condition(), strdup uses malloc which is invisible to PostgreSQL's memory management while pstrdup allocates in the current memory context, which gets cleaned up automatically.

Task: BABEL-6422

Authored by : harshdu@amazon.com
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.

2 participants