Skip to content

Commit

Permalink
fix protect bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen committed Aug 14, 2017
1 parent 6d17b53 commit 7c3ba1d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Version 0.10.13

* Add cleanup script (requested by CRAN)
* Fix PROTECT() bugs from rchk

# Version 0.10.12

Expand Down
6 changes: 3 additions & 3 deletions src/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ RS_DBI_connection* RS_DBI_getConnection(SEXP conHandle) {
SEXP RS_DBI_connectionInfo(SEXP conHandle) {

RS_DBI_connection *con;
SEXP output;
int i;
int n = (int) 8;
char *conDesc[] = {"host", "user", "dbname", "conType",
Expand All @@ -195,7 +194,7 @@ SEXP RS_DBI_connectionInfo(SEXP conHandle) {
con = RS_DBI_getConnection(conHandle);
conLen[7] = con->num_res; /* number of resultSets opened */

output = RS_DBI_createNamedList(conDesc, conType, conLen, n);
SEXP output = PROTECT(RS_DBI_createNamedList(conDesc, conType, conLen, n));

/* dummy */
SET_LST_CHR_EL(output,0,0,mkChar("NA")); /* host */
Expand All @@ -209,7 +208,8 @@ SEXP RS_DBI_connectionInfo(SEXP conHandle) {

for(i=0; i < con->num_res; i++)
LST_INT_EL(output,7,(int) i) = con->resultSetIds[i];


UNPROTECT(1);
return output;
}

Expand Down
3 changes: 2 additions & 1 deletion src/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ SEXP rmysql_driver_valid() {
SEXP rmysql_driver_init(SEXP max_con_, SEXP fetch_default_rec_) {
SEXP mgrHandle = ScalarInteger(0);
if (dbManager) return mgrHandle;
PROTECT(mgrHandle);

int max_con = asInteger(max_con_),
fetch_default_rec = asInteger(fetch_default_rec_);
Expand Down Expand Up @@ -51,7 +52,7 @@ SEXP rmysql_driver_init(SEXP max_con_, SEXP fetch_default_rec_) {
}

dbManager = mgr;

UNPROTECT(1);
return mgrHandle;
}

Expand Down
12 changes: 6 additions & 6 deletions src/result.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ RS_DBI_resultSet* RS_DBI_getResultSet(SEXP rsHandle) {

SEXP RS_DBI_resultSetInfo(SEXP rsHandle) {
RS_DBI_resultSet *result;
SEXP output, flds;
SEXP flds;
int n = (int) 6;
char *rsDesc[] = {"statement", "isSelect", "rowsAffected",
"rowCount", "completed", "fields"};
Expand All @@ -90,15 +90,15 @@ SEXP RS_DBI_resultSetInfo(SEXP rsHandle) {
result = RS_DBI_getResultSet(rsHandle);
flds = R_NilValue;

output = RS_DBI_createNamedList(rsDesc, rsType, rsLen, n);
SEXP output = PROTECT(RS_DBI_createNamedList(rsDesc, rsType, rsLen, n));

SET_LST_CHR_EL(output,0,0,mkChar(result->statement));
LST_INT_EL(output,1,0) = result->isSelect;
LST_INT_EL(output,2,0) = result->rowsAffected;
LST_INT_EL(output,3,0) = result->rowCount;
LST_INT_EL(output,4,0) = result->completed;
SET_ELEMENT(LST_EL(output, 5), (int) 0, flds);

UNPROTECT(1);
return output;
}

Expand Down Expand Up @@ -390,7 +390,7 @@ SEXP RS_MySQL_closeResultSet(SEXP resHandle) {

SEXP RS_MySQL_resultSetInfo(SEXP rsHandle) {
RS_DBI_resultSet *result;
SEXP output, flds;
SEXP flds;
int n = 6;
char *rsDesc[] = {"statement", "isSelect", "rowsAffected",
"rowCount", "completed", "fieldDescription"};
Expand All @@ -401,7 +401,7 @@ SEXP RS_MySQL_resultSetInfo(SEXP rsHandle) {
result = RS_DBI_getResultSet(rsHandle);
flds = R_NilValue;

output = RS_DBI_createNamedList(rsDesc, rsType, rsLen, n);
SEXP output = PROTECT(RS_DBI_createNamedList(rsDesc, rsType, rsLen, n));

SET_LST_CHR_EL(output,0,0,mkChar(result->statement));
LST_INT_EL(output,1,0) = result->isSelect;
Expand All @@ -410,7 +410,7 @@ SEXP RS_MySQL_resultSetInfo(SEXP rsHandle) {
LST_INT_EL(output,4,0) = result->completed;
if(flds != R_NilValue)
SET_ELEMENT(LST_EL(output, 5), (int) 0, flds);

UNPROTECT(1);
return output;
}

Expand Down

0 comments on commit 7c3ba1d

Please sign in to comment.