From 7c3ba1dc8bd59ba972350401f4c421b12da03253 Mon Sep 17 00:00:00 2001 From: Jeroen Date: Mon, 14 Aug 2017 17:58:09 +0200 Subject: [PATCH] fix protect bugs --- NEWS.md | 1 + src/connection.c | 6 +++--- src/driver.c | 3 ++- src/result.c | 12 ++++++------ 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/NEWS.md b/NEWS.md index 3d9464f..361f579 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ # Version 0.10.13 * Add cleanup script (requested by CRAN) + * Fix PROTECT() bugs from rchk # Version 0.10.12 diff --git a/src/connection.c b/src/connection.c index c27e892..657e7b3 100644 --- a/src/connection.c +++ b/src/connection.c @@ -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", @@ -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 */ @@ -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; } diff --git a/src/driver.c b/src/driver.c index 3100d72..4b10ff9 100644 --- a/src/driver.c +++ b/src/driver.c @@ -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_); @@ -51,7 +52,7 @@ SEXP rmysql_driver_init(SEXP max_con_, SEXP fetch_default_rec_) { } dbManager = mgr; - + UNPROTECT(1); return mgrHandle; } diff --git a/src/result.c b/src/result.c index 16f4785..da4e405 100644 --- a/src/result.c +++ b/src/result.c @@ -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"}; @@ -90,7 +90,7 @@ 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; @@ -98,7 +98,7 @@ SEXP RS_DBI_resultSetInfo(SEXP rsHandle) { 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; } @@ -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"}; @@ -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; @@ -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; }