Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9ab942f

Browse files
committedOct 24, 2023
Fix TString and TParameter leaks
1 parent f8e376a commit 9ab942f

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed
 

‎glslang/MachineIndependent/ParseHelper.cpp

+14-16
Original file line numberDiff line numberDiff line change
@@ -932,8 +932,6 @@ TIntermTyped* TParseContext::handleUnaryMath(const TSourceLoc& loc, const char*
932932
return childNode;
933933
}
934934

935-
936-
937935
//
938936
// Handle seeing a base.field dereference in the grammar.
939937
//
@@ -7475,7 +7473,7 @@ void TParseContext::vkRelaxedRemapUniformMembers(const TSourceLoc& loc, const TP
74757473

74767474
ForEachOpaque(type, identifier,
74777475
[&publicType, &loc, this](const TType& type, const TString& path) {
7478-
TString& structMemberName = *(new TString(path));
7476+
TString& structMemberName = *(NewPoolTString(path.c_str()));
74797477

74807478
TArraySizes arraySizes = {};
74817479
if (type.getArraySizes()) arraySizes = *type.getArraySizes();
@@ -7504,30 +7502,29 @@ void TParseContext::vkRelaxedRemapUniformMembers(const TSourceLoc& loc, const TP
75047502
});
75057503
}
75067504

7507-
void TParseContext::vkRelaxedRemapFunctionParameter(const TSourceLoc& loc, TFunction* function, TParameter& param, std::vector<TParameter*>* newParams)
7505+
void TParseContext::vkRelaxedRemapFunctionParameter(const TSourceLoc& loc, TFunction* function, TParameter& param, std::vector<int>* newParams)
75087506
{
75097507
function->addParameter(param);
75107508

75117509
if (!param.type->isStruct() || !param.type->containsOpaque())
75127510
return;
75137511

7514-
75157512
ForEachOpaque(*param.type, (param.name ? *param.name : param.type->getFieldName()),
75167513
[function, param, newParams](const TType& type, const TString& path) {
7517-
TString* memberName = new TString(path);
7514+
TString* memberName = NewPoolTString(path.c_str());
75187515

75197516
TType* memberType = new TType();
75207517
memberType->shallowCopy(type);
75217518
memberType->getQualifier().storage = param.type->getQualifier().storage;
75227519
memberType->clearArraySizes();
75237520

7524-
TParameter* memberParam = new TParameter();
7525-
memberParam->name = memberName;
7526-
memberParam->type = memberType;
7527-
memberParam->defaultValue = nullptr;
7528-
function->addParameter(*memberParam);
7521+
TParameter memberParam = {};
7522+
memberParam.name = memberName;
7523+
memberParam.type = memberType;
7524+
memberParam.defaultValue = nullptr;
7525+
function->addParameter(memberParam);
75297526
if (newParams)
7530-
newParams->push_back(memberParam);
7527+
newParams->push_back(function->getParamCount()-1);
75317528
});
75327529
}
75337530

@@ -7583,7 +7580,7 @@ TIntermNode* TParseContext::vkRelaxedRemapFunctionArgument(const TSourceLoc& loc
75837580
TParameter param = { NewPoolTString(accessChainTraverser.path.c_str()), new TType };
75847581
param.type->shallowCopy(intermTyped->getType());
75857582

7586-
std::vector<TParameter*> newParams = {};
7583+
std::vector<int> newParams = {};
75877584
vkRelaxedRemapFunctionParameter(loc, function, param, &newParams);
75887585

75897586
if (intermTyped->getType().isOpaque())
@@ -7619,15 +7616,16 @@ TIntermNode* TParseContext::vkRelaxedRemapFunctionArgument(const TSourceLoc& loc
76197616
if (!newParams.empty())
76207617
remappedArgument = intermediate.makeAggregate(remappedArgument, loc);
76217618

7622-
for (TParameter* newParam : newParams)
7619+
for (int paramIndex : newParams)
76237620
{
7621+
TParameter& newParam = function->operator[](paramIndex);
76247622
TIntermSymbol* intermSymbol = nullptr;
7625-
TSymbol* symbol = symbolTable.find(*newParam->name);
7623+
TSymbol* symbol = symbolTable.find(*newParam.name);
76267624
if (symbol && symbol->getAsVariable())
76277625
intermSymbol = intermediate.addSymbol(*symbol->getAsVariable(), loc);
76287626
else
76297627
{
7630-
TVariable* variable = new TVariable(newParam->name, *newParam->type);
7628+
TVariable* variable = new TVariable(newParam.name, *newParam.type);
76317629
intermSymbol = intermediate.addSymbol(*variable, loc);
76327630
}
76337631

‎glslang/MachineIndependent/ParseHelper.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ class TParseContext : public TParseContextBase {
369369
// returns true if the variable was remapped to something else
370370
bool vkRelaxedRemapUniformVariable(const TSourceLoc&, TString&, const TPublicType&, TArraySizes*, TIntermTyped*, TType&);
371371
void vkRelaxedRemapUniformMembers(const TSourceLoc&, const TPublicType&, const TType&, const TString&);
372-
void vkRelaxedRemapFunctionParameter(const TSourceLoc&, TFunction*, TParameter&, std::vector<TParameter*>* newParams = nullptr);
372+
void vkRelaxedRemapFunctionParameter(const TSourceLoc&, TFunction*, TParameter&, std::vector<int>* newParams = nullptr);
373373
TIntermNode* vkRelaxedRemapFunctionArgument(const TSourceLoc&, TFunction*, TIntermTyped*);
374374
TIntermTyped* vkRelaxedRemapDotDereference(const TSourceLoc&, TIntermTyped&, const TType&, const TString&);
375375

0 commit comments

Comments
 (0)
Please sign in to comment.