Skip to content

Commit 7da33ca

Browse files
Correct double free error (#141).
1 parent 3406996 commit 7da33ca

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

doc/src/releasenotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Version 4.0.2 (TBD)
99
#) Up to 40 digits can be represented in an unconstrained Oracle number so
1010
allow for that possibility (`cx_Oracle issue 459
1111
<https://github.com/oracle/python-cx_Oracle/issues/459>`__).
12+
#) Correct double free error
13+
(`issue 141 <https://github.com/oracle/odpi/issues/141>`__).
1214
#) Improved documentation.
1315

1416

src/dpiStmt.c

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ int dpiStmt__allocate(dpiConn *conn, int scrollable, dpiStmt **stmt,
5656
// Bind the variable to the statement using either a position or a name. A
5757
// reference to the variable will be retained.
5858
//-----------------------------------------------------------------------------
59-
static int dpiStmt__bind(dpiStmt *stmt, dpiVar *var, int addReference,
60-
uint32_t pos, const char *name, uint32_t nameLength, dpiError *error)
59+
static int dpiStmt__bind(dpiStmt *stmt, dpiVar *var, uint32_t pos,
60+
const char *name, uint32_t nameLength, dpiError *error)
6161
{
6262
dpiBindVar *bindVars, *entry = NULL;
6363
int found, dynamicBind, status;
@@ -148,8 +148,7 @@ static int dpiStmt__bind(dpiStmt *stmt, dpiVar *var, int addReference,
148148
}
149149

150150
// perform actual bind
151-
if (addReference)
152-
dpiGen__setRefCount(var, error, 1);
151+
dpiGen__setRefCount(var, error, 1);
153152
entry->var = var;
154153
dynamicBind = stmt->isReturning || var->isDynamic;
155154
if (pos > 0) {
@@ -368,6 +367,7 @@ static int dpiStmt__createBindVar(dpiStmt *stmt,
368367
dpiData *varData;
369368
dpiVar *tempVar;
370369
uint32_t size;
370+
int status;
371371

372372
// determine the type (and size) of bind variable to create
373373
size = 0;
@@ -418,13 +418,11 @@ static int dpiStmt__createBindVar(dpiStmt *stmt,
418418
return DPI_FAILURE;
419419

420420
// bind variable to statement
421-
if (dpiStmt__bind(stmt, tempVar, 0, pos, name, nameLength, error) < 0) {
422-
dpiVar__free(tempVar, error);
423-
return DPI_FAILURE;
424-
}
425-
426-
*var = tempVar;
427-
return DPI_SUCCESS;
421+
status = dpiStmt__bind(stmt, tempVar, pos, name, nameLength, error);
422+
dpiGen__setRefCount(tempVar, error, -1);
423+
if (status == DPI_SUCCESS)
424+
*var = tempVar;
425+
return status;
428426
}
429427

430428

@@ -1057,7 +1055,7 @@ static int dpiStmt__reExecute(dpiStmt *stmt, uint32_t numIters,
10571055
continue;
10581056
var = bindVar->var;
10591057
bindVar->var = NULL;
1060-
if (dpiStmt__bind(stmt, var, 0, bindVar->pos, bindVar->name,
1058+
if (dpiStmt__bind(stmt, var, bindVar->pos, bindVar->name,
10611059
bindVar->nameLength, error) < 0) {
10621060
dpiGen__setRefCount(var, error, -1);
10631061
return DPI_FAILURE;
@@ -1094,7 +1092,7 @@ int dpiStmt_bindByName(dpiStmt *stmt, const char *name, uint32_t nameLength,
10941092
DPI_CHECK_PTR_NOT_NULL(stmt, name)
10951093
if (dpiGen__checkHandle(var, DPI_HTYPE_VAR, "bind by name", &error) < 0)
10961094
return dpiGen__endPublicFn(stmt, DPI_FAILURE, &error);
1097-
status = dpiStmt__bind(stmt, var, 1, 0, name, nameLength, &error);
1095+
status = dpiStmt__bind(stmt, var, 0, name, nameLength, &error);
10981096
return dpiGen__endPublicFn(stmt, status, &error);
10991097
}
11001098

@@ -1112,7 +1110,7 @@ int dpiStmt_bindByPos(dpiStmt *stmt, uint32_t pos, dpiVar *var)
11121110
return dpiGen__endPublicFn(stmt, DPI_FAILURE, &error);
11131111
if (dpiGen__checkHandle(var, DPI_HTYPE_VAR, "bind by pos", &error) < 0)
11141112
return dpiGen__endPublicFn(stmt, DPI_FAILURE, &error);
1115-
status = dpiStmt__bind(stmt, var, 1, pos, NULL, 0, &error);
1113+
status = dpiStmt__bind(stmt, var, pos, NULL, 0, &error);
11161114
return dpiGen__endPublicFn(stmt, status, &error);
11171115
}
11181116

@@ -1132,10 +1130,8 @@ int dpiStmt_bindValueByName(dpiStmt *stmt, const char *name,
11321130
return dpiGen__endPublicFn(stmt, DPI_FAILURE, &error);
11331131
DPI_CHECK_PTR_NOT_NULL(stmt, name)
11341132
DPI_CHECK_PTR_NOT_NULL(stmt, data)
1135-
if (dpiStmt__createBindVar(stmt, nativeTypeNum, data, &var, 0, name,
1136-
nameLength, &error) < 0)
1137-
return dpiGen__endPublicFn(stmt, DPI_FAILURE, &error);
1138-
status = dpiStmt__bind(stmt, var, 1, 0, name, nameLength, &error);
1133+
status = dpiStmt__createBindVar(stmt, nativeTypeNum, data, &var, 0, name,
1134+
nameLength, &error);
11391135
return dpiGen__endPublicFn(stmt, status, &error);
11401136
}
11411137

@@ -1154,10 +1150,8 @@ int dpiStmt_bindValueByPos(dpiStmt *stmt, uint32_t pos,
11541150
if (dpiStmt__check(stmt, __func__, &error) < 0)
11551151
return dpiGen__endPublicFn(stmt, DPI_FAILURE, &error);
11561152
DPI_CHECK_PTR_NOT_NULL(stmt, data)
1157-
if (dpiStmt__createBindVar(stmt, nativeTypeNum, data, &var, pos, NULL, 0,
1158-
&error) < 0)
1159-
return dpiGen__endPublicFn(stmt, DPI_FAILURE, &error);
1160-
status = dpiStmt__bind(stmt, var, 1, pos, NULL, 0, &error);
1153+
status = dpiStmt__createBindVar(stmt, nativeTypeNum, data, &var, pos, NULL,
1154+
0, &error);
11611155
return dpiGen__endPublicFn(stmt, status, &error);
11621156
}
11631157

0 commit comments

Comments
 (0)