mirror of
https://github.com/pocoproject/poco.git
synced 2025-02-22 07:01:12 +01:00
SF [2019857] Memory leak in Data::ODBC Extractor
This commit is contained in:
parent
93c6bb0725
commit
f574e90f41
@ -368,49 +368,58 @@ bool Extractor::extractManualImpl<std::string>(std::size_t pos, std::string& val
|
|||||||
std::size_t totalSize = 0;
|
std::size_t totalSize = 0;
|
||||||
|
|
||||||
SQLLEN len;
|
SQLLEN len;
|
||||||
std::auto_ptr<char> apChar(new char[CHUNK_SIZE]);
|
char* pChar = 0;
|
||||||
char* pChar = apChar.get();
|
try
|
||||||
SQLRETURN rc = 0;
|
|
||||||
|
|
||||||
val.clear();
|
|
||||||
resizeLengths(pos);
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
std::memset(pChar, 0, CHUNK_SIZE);
|
pChar = new char[CHUNK_SIZE];
|
||||||
len = 0;
|
SQLRETURN rc = 0;
|
||||||
rc = SQLGetData(_rStmt,
|
|
||||||
(SQLUSMALLINT) pos + 1,
|
val.clear();
|
||||||
cType, //C data type
|
resizeLengths(pos);
|
||||||
pChar, //returned value
|
|
||||||
CHUNK_SIZE, //buffer length
|
|
||||||
&len); //length indicator
|
|
||||||
|
|
||||||
if (SQL_NO_DATA != rc && Utility::isError(rc))
|
do
|
||||||
throw StatementException(_rStmt, "SQLGetData()");
|
|
||||||
|
|
||||||
if (SQL_NO_TOTAL == len)//unknown length, throw
|
|
||||||
throw UnknownDataLengthException("Could not determine returned data length.");
|
|
||||||
|
|
||||||
if (isNullLengthIndicator(len))
|
|
||||||
{
|
{
|
||||||
_lengths[pos] = len;
|
std::memset(pChar, 0, CHUNK_SIZE);
|
||||||
return false;
|
len = 0;
|
||||||
}
|
rc = SQLGetData(_rStmt,
|
||||||
|
(SQLUSMALLINT) pos + 1,
|
||||||
|
cType, //C data type
|
||||||
|
pChar, //returned value
|
||||||
|
CHUNK_SIZE, //buffer length
|
||||||
|
&len); //length indicator
|
||||||
|
|
||||||
if (SQL_NO_DATA == rc || !len)
|
if (SQL_NO_DATA != rc && Utility::isError(rc))
|
||||||
break;
|
throw StatementException(_rStmt, "SQLGetData()");
|
||||||
|
|
||||||
_lengths[pos] += len;
|
if (SQL_NO_TOTAL == len)//unknown length, throw
|
||||||
fetchedSize = _lengths[pos] > CHUNK_SIZE ? CHUNK_SIZE : _lengths[pos];
|
throw UnknownDataLengthException("Could not determine returned data length.");
|
||||||
totalSize += fetchedSize;
|
|
||||||
if (totalSize <= maxSize)
|
|
||||||
val.append(pChar, fetchedSize);
|
|
||||||
else
|
|
||||||
throw DataException(format(FLD_SIZE_EXCEEDED_FMT, fetchedSize, maxSize));
|
|
||||||
}while (true);
|
|
||||||
|
|
||||||
return true;
|
if (isNullLengthIndicator(len))
|
||||||
|
{
|
||||||
|
_lengths[pos] = len;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SQL_NO_DATA == rc || !len)
|
||||||
|
break;
|
||||||
|
|
||||||
|
_lengths[pos] += len;
|
||||||
|
fetchedSize = _lengths[pos] > CHUNK_SIZE ? CHUNK_SIZE : _lengths[pos];
|
||||||
|
totalSize += fetchedSize;
|
||||||
|
if (totalSize <= maxSize)
|
||||||
|
val.append(pChar, fetchedSize);
|
||||||
|
else
|
||||||
|
throw DataException(format(FLD_SIZE_EXCEEDED_FMT, fetchedSize, maxSize));
|
||||||
|
}while (true);
|
||||||
|
|
||||||
|
delete[] pChar;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} catch (...)
|
||||||
|
{
|
||||||
|
delete[] pChar;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -424,48 +433,57 @@ bool Extractor::extractManualImpl<Poco::Data::BLOB>(std::size_t pos,
|
|||||||
std::size_t totalSize = 0;
|
std::size_t totalSize = 0;
|
||||||
|
|
||||||
SQLLEN len;
|
SQLLEN len;
|
||||||
std::auto_ptr<char> apChar(new char[CHUNK_SIZE]);
|
char* pChar = 0;
|
||||||
char* pChar = apChar.get();
|
try
|
||||||
SQLRETURN rc = 0;
|
|
||||||
|
|
||||||
val.clear();
|
|
||||||
resizeLengths(pos);
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
std::memset(pChar, 0, CHUNK_SIZE);
|
pChar = new char[CHUNK_SIZE];
|
||||||
len = 0;
|
SQLRETURN rc = 0;
|
||||||
rc = SQLGetData(_rStmt,
|
|
||||||
(SQLUSMALLINT) pos + 1,
|
|
||||||
cType, //C data type
|
|
||||||
pChar, //returned value
|
|
||||||
CHUNK_SIZE, //buffer length
|
|
||||||
&len); //length indicator
|
|
||||||
|
|
||||||
_lengths[pos] += len;
|
val.clear();
|
||||||
|
resizeLengths(pos);
|
||||||
|
|
||||||
if (SQL_NO_DATA != rc && Utility::isError(rc))
|
do
|
||||||
throw StatementException(_rStmt, "SQLGetData()");
|
{
|
||||||
|
std::memset(pChar, 0, CHUNK_SIZE);
|
||||||
|
len = 0;
|
||||||
|
rc = SQLGetData(_rStmt,
|
||||||
|
(SQLUSMALLINT) pos + 1,
|
||||||
|
cType, //C data type
|
||||||
|
pChar, //returned value
|
||||||
|
CHUNK_SIZE, //buffer length
|
||||||
|
&len); //length indicator
|
||||||
|
|
||||||
|
_lengths[pos] += len;
|
||||||
|
|
||||||
if (SQL_NO_TOTAL == len)//unknown length, throw
|
if (SQL_NO_DATA != rc && Utility::isError(rc))
|
||||||
throw UnknownDataLengthException("Could not determine returned data length.");
|
throw StatementException(_rStmt, "SQLGetData()");
|
||||||
|
|
||||||
if (isNullLengthIndicator(len))
|
if (SQL_NO_TOTAL == len)//unknown length, throw
|
||||||
return false;
|
throw UnknownDataLengthException("Could not determine returned data length.");
|
||||||
|
|
||||||
if (SQL_NO_DATA == rc || !len)
|
if (isNullLengthIndicator(len))
|
||||||
break;
|
return false;
|
||||||
|
|
||||||
fetchedSize = len > CHUNK_SIZE ? CHUNK_SIZE : len;
|
if (SQL_NO_DATA == rc || !len)
|
||||||
totalSize += fetchedSize;
|
break;
|
||||||
if (totalSize <= maxSize)
|
|
||||||
val.appendRaw(pChar, fetchedSize);
|
|
||||||
else
|
|
||||||
throw DataException(format(FLD_SIZE_EXCEEDED_FMT, fetchedSize, maxSize));
|
|
||||||
|
|
||||||
}while (true);
|
fetchedSize = len > CHUNK_SIZE ? CHUNK_SIZE : len;
|
||||||
|
totalSize += fetchedSize;
|
||||||
|
if (totalSize <= maxSize)
|
||||||
|
val.appendRaw(pChar, fetchedSize);
|
||||||
|
else
|
||||||
|
throw DataException(format(FLD_SIZE_EXCEEDED_FMT, fetchedSize, maxSize));
|
||||||
|
|
||||||
return true;
|
}while (true);
|
||||||
|
|
||||||
|
delete[] pChar;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} catch (...)
|
||||||
|
{
|
||||||
|
delete[] pChar;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user