Skip to content

Commit 7c3ba1d

Browse files
committed
fix protect bugs
1 parent 6d17b53 commit 7c3ba1d

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Version 0.10.13
22

33
* Add cleanup script (requested by CRAN)
4+
* Fix PROTECT() bugs from rchk
45

56
# Version 0.10.12
67

src/connection.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ RS_DBI_connection* RS_DBI_getConnection(SEXP conHandle) {
181181
SEXP RS_DBI_connectionInfo(SEXP conHandle) {
182182

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

198-
output = RS_DBI_createNamedList(conDesc, conType, conLen, n);
197+
SEXP output = PROTECT(RS_DBI_createNamedList(conDesc, conType, conLen, n));
199198

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

210209
for(i=0; i < con->num_res; i++)
211210
LST_INT_EL(output,7,(int) i) = con->resultSetIds[i];
212-
211+
212+
UNPROTECT(1);
213213
return output;
214214
}
215215

src/driver.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ SEXP rmysql_driver_valid() {
1717
SEXP rmysql_driver_init(SEXP max_con_, SEXP fetch_default_rec_) {
1818
SEXP mgrHandle = ScalarInteger(0);
1919
if (dbManager) return mgrHandle;
20+
PROTECT(mgrHandle);
2021

2122
int max_con = asInteger(max_con_),
2223
fetch_default_rec = asInteger(fetch_default_rec_);
@@ -51,7 +52,7 @@ SEXP rmysql_driver_init(SEXP max_con_, SEXP fetch_default_rec_) {
5152
}
5253

5354
dbManager = mgr;
54-
55+
UNPROTECT(1);
5556
return mgrHandle;
5657
}
5758

src/result.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ RS_DBI_resultSet* RS_DBI_getResultSet(SEXP rsHandle) {
7979

8080
SEXP RS_DBI_resultSetInfo(SEXP rsHandle) {
8181
RS_DBI_resultSet *result;
82-
SEXP output, flds;
82+
SEXP flds;
8383
int n = (int) 6;
8484
char *rsDesc[] = {"statement", "isSelect", "rowsAffected",
8585
"rowCount", "completed", "fields"};
@@ -90,15 +90,15 @@ SEXP RS_DBI_resultSetInfo(SEXP rsHandle) {
9090
result = RS_DBI_getResultSet(rsHandle);
9191
flds = R_NilValue;
9292

93-
output = RS_DBI_createNamedList(rsDesc, rsType, rsLen, n);
93+
SEXP output = PROTECT(RS_DBI_createNamedList(rsDesc, rsType, rsLen, n));
9494

9595
SET_LST_CHR_EL(output,0,0,mkChar(result->statement));
9696
LST_INT_EL(output,1,0) = result->isSelect;
9797
LST_INT_EL(output,2,0) = result->rowsAffected;
9898
LST_INT_EL(output,3,0) = result->rowCount;
9999
LST_INT_EL(output,4,0) = result->completed;
100100
SET_ELEMENT(LST_EL(output, 5), (int) 0, flds);
101-
101+
UNPROTECT(1);
102102
return output;
103103
}
104104

@@ -390,7 +390,7 @@ SEXP RS_MySQL_closeResultSet(SEXP resHandle) {
390390

391391
SEXP RS_MySQL_resultSetInfo(SEXP rsHandle) {
392392
RS_DBI_resultSet *result;
393-
SEXP output, flds;
393+
SEXP flds;
394394
int n = 6;
395395
char *rsDesc[] = {"statement", "isSelect", "rowsAffected",
396396
"rowCount", "completed", "fieldDescription"};
@@ -401,7 +401,7 @@ SEXP RS_MySQL_resultSetInfo(SEXP rsHandle) {
401401
result = RS_DBI_getResultSet(rsHandle);
402402
flds = R_NilValue;
403403

404-
output = RS_DBI_createNamedList(rsDesc, rsType, rsLen, n);
404+
SEXP output = PROTECT(RS_DBI_createNamedList(rsDesc, rsType, rsLen, n));
405405

406406
SET_LST_CHR_EL(output,0,0,mkChar(result->statement));
407407
LST_INT_EL(output,1,0) = result->isSelect;
@@ -410,7 +410,7 @@ SEXP RS_MySQL_resultSetInfo(SEXP rsHandle) {
410410
LST_INT_EL(output,4,0) = result->completed;
411411
if(flds != R_NilValue)
412412
SET_ELEMENT(LST_EL(output, 5), (int) 0, flds);
413-
413+
UNPROTECT(1);
414414
return output;
415415
}
416416

0 commit comments

Comments
 (0)