summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNorbert Thiebaud <nthiebaud@gmail.com>2014-06-27 23:35:21 +0200
committerNorbert Thiebaud <nthiebaud@gmail.com>2014-06-27 23:37:51 +0200
commitf7453024e1f46a038d1278ddcbba64ccdbf8dcd1 (patch)
tree6bec6bc9bfdef90429fa599a51a2470d69a68424
parent939ce4afbb36673e03e90881c48fd4e2bbb74bb8 (diff)
fdo#80574 firebird memory management issues
Change-Id: I37438cd3f9c8e197e5a3aa3d9cbcc5bf3681d792
-rw-r--r--connectivity/source/drivers/firebird/PreparedStatement.cxx4
-rw-r--r--connectivity/source/drivers/firebird/StatementCommonBase.cxx115
-rw-r--r--connectivity/source/drivers/firebird/Util.cxx14
3 files changed, 76 insertions, 57 deletions
diff --git a/connectivity/source/drivers/firebird/PreparedStatement.cxx b/connectivity/source/drivers/firebird/PreparedStatement.cxx
index d5e1213a93a6..3c40ecd237a1 100644
--- a/connectivity/source/drivers/firebird/PreparedStatement.cxx
+++ b/connectivity/source/drivers/firebird/PreparedStatement.cxx
@@ -76,7 +76,7 @@ void OPreparedStatement::ensurePrepared()
if (!m_pInSqlda)
{
- m_pInSqlda = (XSQLDA*) malloc(XSQLDA_LENGTH(10));
+ m_pInSqlda = (XSQLDA*) calloc(1, XSQLDA_LENGTH(10));
m_pInSqlda->version = SQLDA_VERSION1;
m_pInSqlda->sqln = 10;
}
@@ -99,7 +99,7 @@ void OPreparedStatement::ensurePrepared()
{
short nItems = m_pInSqlda->sqld;
free(m_pInSqlda);
- m_pInSqlda = (XSQLDA*) malloc(XSQLDA_LENGTH(nItems));
+ m_pInSqlda = (XSQLDA*) calloc(1, XSQLDA_LENGTH(nItems));
m_pInSqlda->version = SQLDA_VERSION1;
m_pInSqlda->sqln = nItems;
isc_dsql_describe_bind(m_statusVector,
diff --git a/connectivity/source/drivers/firebird/StatementCommonBase.cxx b/connectivity/source/drivers/firebird/StatementCommonBase.cxx
index 49415fac4954..5daa56da013c 100644
--- a/connectivity/source/drivers/firebird/StatementCommonBase.cxx
+++ b/connectivity/source/drivers/firebird/StatementCommonBase.cxx
@@ -133,7 +133,7 @@ void OStatementCommonBase::prepareAndDescribeStatement(const OUString& sql,
if (!pOutSqlda)
{
- pOutSqlda = (XSQLDA*) malloc(XSQLDA_LENGTH(10));
+ pOutSqlda = (XSQLDA*) calloc(1, XSQLDA_LENGTH(10));
pOutSqlda->version = SQLDA_VERSION1;
pOutSqlda->sqln = 10;
}
@@ -146,68 +146,79 @@ void OStatementCommonBase::prepareAndDescribeStatement(const OUString& sql,
if (aErr)
{
- free(pOutSqlda);
- pOutSqlda = 0;
evaluateStatusVector(m_statusVector,
"isc_dsql_allocate_statement",
*this);
}
-
- aErr = isc_dsql_prepare(m_statusVector,
- &m_pConnection->getTransaction(),
- &m_aStatementHandle,
- 0,
- OUStringToOString(sql, RTL_TEXTENCODING_UTF8).getStr(),
- FIREBIRD_SQL_DIALECT,
- pInSqlda);
-
- if (aErr)
+ else
{
- // TODO: free statement handle?
- free(pOutSqlda);
- pOutSqlda = 0;
- evaluateStatusVector(m_statusVector,
- "isc_dsql_prepare",
- *this);
- }
-
- aErr = isc_dsql_describe(m_statusVector,
- &m_aStatementHandle,
- 1,
- pOutSqlda);
+ aErr = isc_dsql_prepare(m_statusVector,
+ &m_pConnection->getTransaction(),
+ &m_aStatementHandle,
+ 0,
+ OUStringToOString(sql, RTL_TEXTENCODING_UTF8).getStr(),
+ FIREBIRD_SQL_DIALECT,
+ pInSqlda);
+ if (aErr)
+ {
+ evaluateStatusVector(m_statusVector,
+ "isc_dsql_prepare",
+ *this);
+ }
+ else
+ {
+ aErr = isc_dsql_describe(m_statusVector,
+ &m_aStatementHandle,
+ 1,
+ pOutSqlda);
- if (aErr)
- {
- // TODO: free statement handle, etc.?
- free(pOutSqlda);
- pOutSqlda = 0;
- evaluateStatusVector(m_statusVector,
- "isc_dsql_describe",
- *this);
+ if (aErr)
+ {
+ // TODO: free statement handle, etc.?
+ evaluateStatusVector(m_statusVector,
+ "isc_dsql_describe",
+ *this);
+ }
+ else
+ {
+ // Ensure we have enough space in pOutSqlda
+ if (pOutSqlda->sqld > pOutSqlda->sqln)
+ {
+ int n = pOutSqlda->sqld;
+ free(pOutSqlda);
+ pOutSqlda = (XSQLDA*) calloc(1, XSQLDA_LENGTH(n));
+ pOutSqlda->version = SQLDA_VERSION1;
+ pOutSqlda->sqln = n;
+ aErr = isc_dsql_describe(m_statusVector,
+ &m_aStatementHandle,
+ 1,
+ pOutSqlda);
+ }
+
+ // Process each XSQLVAR parameter structure in the output XSQLDA
+ if (aErr)
+ {
+ evaluateStatusVector(m_statusVector,
+ "isc_dsql_describe",
+ *this);
+ }
+ else
+ {
+ mallocSQLVAR(pOutSqlda);
+ }
+ }
+ }
+ if(aErr)
+ {
+ freeStatementHandle();
+ }
}
-
- // Ensure we have enough space in pOutSqlda
- if (pOutSqlda->sqld > pOutSqlda->sqln)
+ if(aErr)
{
- int n = pOutSqlda->sqld;
free(pOutSqlda);
- pOutSqlda = (XSQLDA*) malloc(XSQLDA_LENGTH(n));
- pOutSqlda->version = SQLDA_VERSION1;
- pOutSqlda->sqln = n;
- aErr = isc_dsql_describe(m_statusVector,
- &m_aStatementHandle,
- 1,
- pOutSqlda);
+ pOutSqlda = NULL;
}
-
- // Process each XSQLVAR parameter structure in the output XSQLDA
- if (aErr)
- evaluateStatusVector(m_statusVector,
- "isc_dsql_describe",
- *this);
-
- mallocSQLVAR(pOutSqlda);
}
// ---- XMultipleResults - UNSUPPORTED ----------------------------------------
diff --git a/connectivity/source/drivers/firebird/Util.cxx b/connectivity/source/drivers/firebird/Util.cxx
index 74eb00c8b385..9a138570cd1d 100644
--- a/connectivity/source/drivers/firebird/Util.cxx
+++ b/connectivity/source/drivers/firebird/Util.cxx
@@ -271,7 +271,11 @@ void firebird::freeSQLVAR(XSQLDA* pSqlda)
case SQL_INT64:
case SQL_TYPE_TIME:
case SQL_TYPE_DATE:
- free(pVar->sqldata);
+ if(pVar->sqldata)
+ {
+ free(pVar->sqldata);
+ pVar->sqldata = NULL;
+ }
break;
case SQL_ARRAY:
assert(false); // TODO: implement
@@ -284,13 +288,17 @@ void firebird::freeSQLVAR(XSQLDA* pSqlda)
break;
default:
SAL_WARN("connectivity.firebird", "Unknown type: " << dtype);
- assert(false);
+// assert(false);
break;
}
if (pVar->sqltype & 1)
{
- free(pVar->sqlind);
+ if(pVar->sqlind)
+ {
+ free(pVar->sqlind);
+ pVar->sqlind = NULL;
+ }
}
}
}