Changeset: 1bc1cd0ca2af for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1bc1cd0ca2af
Modified Files:
clients/odbc/driver/ODBCConvert.c
clients/odbc/driver/SQLExecute.c
Branch: Jul2012
Log Message:
Fix resource leakage in case of error.
Found by coverity.
diffs (73 lines):
diff --git a/clients/odbc/driver/ODBCConvert.c
b/clients/odbc/driver/ODBCConvert.c
--- a/clients/odbc/driver/ODBCConvert.c
+++ b/clients/odbc/driver/ODBCConvert.c
@@ -2683,12 +2683,14 @@ ODBCFetch(ODBCStmt *stmt,
#define assign(buf,bufpos,buflen,value,stmt) \
do { \
if (bufpos >= buflen) { \
- buf = realloc(buf, buflen += 1024); \
- if (buf == NULL) { \
+ char *b = realloc(buf, buflen += 1024); \
+ if (b == NULL) { \
+ free(buf); \
/* Memory allocation error */ \
addStmtError(stmt, "HY001", NULL, 0); \
return SQL_ERROR; \
} \
+ buf = b; \
} \
buf[bufpos++] = (value); \
} while (0)
@@ -2697,12 +2699,14 @@ ODBCFetch(ODBCStmt *stmt,
size_t _len = strlen(value); \
size_t _i; \
while (bufpos + _len >= buflen) { \
- buf = realloc(buf, buflen += 1024); \
- if (buf == NULL) { \
+ char *b = realloc(buf, buflen += 1024); \
+ if (b == NULL) { \
+ free(buf); \
/* Memory allocation error */ \
addStmtError(stmt, "HY001", NULL, 0); \
return SQL_ERROR; \
} \
+ buf = b; \
} \
for (_i = 0; _i < _len; _i++) \
buf[bufpos++] = (value)[_i]; \
@@ -3016,6 +3020,7 @@ ODBCStore(ODBCStmt *stmt,
}
assigns(buf, bufpos, buflen, sep, stmt);
+ *bufp = buf;
/* just the types supported by the server */
switch (sqltype) {
case SQL_CHAR:
diff --git a/clients/odbc/driver/SQLExecute.c b/clients/odbc/driver/SQLExecute.c
--- a/clients/odbc/driver/SQLExecute.c
+++ b/clients/odbc/driver/SQLExecute.c
@@ -421,16 +421,21 @@ SQLExecute_(ODBCStmt *stmt)
offset = 0;
sep = "";
for (i = 1; i <= stmt->nparams; i++) {
- if (ODBCStore(stmt, i, offset, 0, &query, &querypos, &querylen,
sep) == SQL_ERROR)
+ if (ODBCStore(stmt, i, offset, 0, &query, &querypos, &querylen,
sep) == SQL_ERROR) {
+ if (query)
+ free(query);
return SQL_ERROR;
+ }
sep = ",";
}
if (querypos + 1 >= querylen) {
- query = realloc(query, querylen += 10);
- if (query == NULL) {
+ char *q = realloc(query, querylen += 10);
+ if (q == NULL) {
+ free(query);
addStmtError(stmt, "HY001", NULL, 0);
return SQL_ERROR;
}
+ query = q;
}
query[querypos++] = ')';
query[querypos] = 0;
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list