Skip to content

Commit

Permalink
Replace more spurious strdups with pstrdups (#7441)
Browse files Browse the repository at this point in the history
DESCRIPTION: Remove a few small memory leaks

In #7440 one instance of a strdup was removed. But there were a few
more. This removes the ones that are left over, or adds a comment why
strdup is on purpose.

(cherry picked from commit 9683bef)
  • Loading branch information
JelteF committed Apr 16, 2024
1 parent 6c14879 commit 0b2e0cd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/backend/distributed/commands/extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ PreprocessCreateExtensionStmtForCitusColumnar(Node *parsetree)
/*create extension citus version xxx*/
if (newVersionValue)
{
char *newVersion = strdup(defGetString(newVersionValue));
char *newVersion = pstrdup(defGetString(newVersionValue));
versionNumber = GetExtensionVersionNumber(newVersion);
}

Expand All @@ -796,7 +796,7 @@ PreprocessCreateExtensionStmtForCitusColumnar(Node *parsetree)
Oid citusOid = get_extension_oid("citus", true);
if (citusOid != InvalidOid)
{
char *curCitusVersion = strdup(get_extension_version(citusOid));
char *curCitusVersion = pstrdup(get_extension_version(citusOid));
int curCitusVersionNum = GetExtensionVersionNumber(curCitusVersion);
if (curCitusVersionNum < 1110)
{
Expand Down Expand Up @@ -891,7 +891,7 @@ PreprocessAlterExtensionCitusStmtForCitusColumnar(Node *parseTree)
if (newVersionValue)
{
char *newVersion = defGetString(newVersionValue);
double newVersionNumber = GetExtensionVersionNumber(strdup(newVersion));
double newVersionNumber = GetExtensionVersionNumber(pstrdup(newVersion));

/*alter extension citus update to version >= 11.1-1, and no citus_columnar installed */
if (newVersionNumber >= 1110 && citusColumnarOid == InvalidOid)
Expand Down Expand Up @@ -935,7 +935,7 @@ PostprocessAlterExtensionCitusStmtForCitusColumnar(Node *parseTree)
if (newVersionValue)
{
char *newVersion = defGetString(newVersionValue);
double newVersionNumber = GetExtensionVersionNumber(strdup(newVersion));
double newVersionNumber = GetExtensionVersionNumber(pstrdup(newVersion));
if (newVersionNumber >= 1110 && citusColumnarOid != InvalidOid)
{
/*upgrade citus, after "ALTER EXTENSION citus update to xxx" updates citus_columnar Y to version Z. */
Expand Down
4 changes: 4 additions & 0 deletions src/backend/distributed/connection/connection_configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ AddConnParam(const char *keyword, const char *value)
errmsg("ConnParams arrays bound check failed")));
}

/*
* Don't use pstrdup here to avoid being tied to a memory context, we free
* these later using ResetConnParams
*/
ConnParams.keywords[ConnParams.size] = strdup(keyword);
ConnParams.values[ConnParams.size] = strdup(value);
ConnParams.size++;
Expand Down
2 changes: 1 addition & 1 deletion src/backend/distributed/planner/query_colocation_checker.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ CreateTargetEntryForNullCol(Form_pg_attribute attributeTuple, int resno)
attributeTuple->attcollation);
char *resName = attributeTuple->attname.data;
TargetEntry *targetEntry =
makeTargetEntry(nullExpr, resno, strdup(resName), false);
makeTargetEntry(nullExpr, resno, pstrdup(resName), false);
return targetEntry;
}

Expand Down

0 comments on commit 0b2e0cd

Please sign in to comment.