Skip to content

Commit 2a01e05

Browse files
Fixing memory leaks observed in ASan (#4690) (#4693)
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
1 parent b59c594 commit 2a01e05

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1638,7 +1638,7 @@ PrepareRowDescription(TupleDesc typeinfo, PlannedStmt *plannedstmt, List *target
16381638
if (relMetaDataInfo->partName[1] == NULL)
16391639
{
16401640
if (physical_schema_name != NULL)
1641-
relMetaDataInfo->partName[1] = strdup(physical_schema_name);
1641+
relMetaDataInfo->partName[1] = pstrdup(physical_schema_name);
16421642
else
16431643
relMetaDataInfo->partName[1] = NULL;
16441644
}

contrib/babelfishpg_tsql/src/tsqlIface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3009,7 +3009,7 @@ class tsqlBuilder : public tsqlCommonMutator
30093009
clear_rewritten_query_fragment();
30103010

30113011
/* Now we can prepend SELECT to rewritten search_condition */
3012-
expr->query = strdup((std::string("SELECT ") + std::string(expr->query)).c_str());
3012+
expr->query = pstrdup((std::string("SELECT ") + std::string(expr->query)).c_str());
30133013
return expr;
30143014
}
30153015

0 commit comments

Comments
 (0)