Skip to content

Commit

Permalink
ExprPixelFunc(): fix memory leak in error code path
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault authored and dbaston committed Jan 11, 2025
1 parent dc1c658 commit d548b4d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions frmts/vrt/pixelfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1675,14 +1675,16 @@ static CPLErr ExprPixelFunc(void **papoSources, int nSources, void *pData,
&adfValuesForPixel[iSource++]);
}
}
CPLString osExpression(pszExpression);
if (osExpression.find("BANDS") != std::string::npos)

if (strstr(pszExpression, "BANDS"))
{
poExpression->RegisterVector("BANDS", &adfValuesForPixel);
}

double *padfResults =
static_cast<double *>(CPLMalloc(nXSize * sizeof(double)));
std::unique_ptr<double, VSIFreeReleaser> padfResults(
static_cast<double *>(VSI_MALLOC2_VERBOSE(nXSize, sizeof(double))));
if (!padfResults)
return CE_Failure;

/* ---- Set pixels ---- */
size_t ii = 0;
Expand All @@ -1703,18 +1705,16 @@ static CPLErr ExprPixelFunc(void **papoSources, int nSources, void *pData,
}
else
{
padfResults[iCol] = poExpression->Results()[0];
padfResults.get()[iCol] = poExpression->Results()[0];
}
}

GDALCopyWords(padfResults, GDT_Float64, sizeof(double),
GDALCopyWords(padfResults.get(), GDT_Float64, sizeof(double),
static_cast<GByte *>(pData) +
static_cast<GSpacing>(nLineSpace) * iLine,
eBufType, nPixelSpace, nXSize);
}

CPLFree(padfResults);

/* ---- Return success ---- */
return CE_None;
} // ExprPixelFunc
Expand Down

0 comments on commit d548b4d

Please sign in to comment.