Skip to content

Commit

Permalink
fix: Fix valgrind error (#552)
Browse files Browse the repository at this point in the history
* fix: Fix valgrind error

* Function pointer safety

* Add patch

* Build-ignore
  • Loading branch information
krlmlr authored Nov 30, 2024
1 parent 9a058f2 commit db32888
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ a.out.dSYM
^\.gitpod\.yml$
^src/CMakeLists\.txt$
^\.aviator/config\.yml$
^patch$
5 changes: 5 additions & 0 deletions data-raw/upgrade.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ register_misc_extension("series")
register_misc_extension("csv")
register_misc_extension("uuid")

for (f in dir("patch", full.names = TRUE)) {
message("Applying ", f)
stopifnot(system(paste0("patch -p1 -i ", f)) == 0)
}

if (any(grepl("^src/", gert::git_status()$file))) {
gert::git_add("src")

Expand Down
26 changes: 26 additions & 0 deletions patch/0001-Function-pointer-safety.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
From 3a9012f07d9f7da290809d89549b663a75fd4e6b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kirill=20M=C3=BCller?= <[email protected]>
Date: Sat, 30 Nov 2024 20:04:14 +0100
Subject: [PATCH] Function pointer safety

---
src/vendor/extensions/regexp.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/vendor/extensions/regexp.c b/src/vendor/extensions/regexp.c
index 18266493..340357ea 100644
--- a/src/vendor/extensions/regexp.c
+++ b/src/vendor/extensions/regexp.c
@@ -656,7 +656,8 @@ static const char *re_subcompile_string(ReCompiled *p){
** regular expression. Applications should invoke this routine once
** for every call to re_compile() to avoid memory leaks.
*/
-static void re_free(ReCompiled *pRe){
+static void re_free(void *pRe_){
+ ReCompiled *pRe = (ReCompiled*)pRe_;
if( pRe ){
sqlite3_free(pRe->aOp);
sqlite3_free(pRe->aArg);
--
2.43.0

12 changes: 11 additions & 1 deletion src/import-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ RS_sqlite_import(
}
in = fopen(zFile, "rb");
if (in == 0) {
Rf_error("RS_sqlite_import: cannot open file %s", zFile);
fclose(in);
sqlite3_finalize(pStmt);
Rf_error("RS_sqlite_import: cannot open file %s", zFile);
}
azCol = malloc(sizeof(azCol[0]) * (nCol + 1));
if (azCol == 0) return 0;
Expand All @@ -105,6 +106,10 @@ RS_sqlite_import(
}
}
if (i + 1 != nCol) {
free(zLine);
free(azCol);
fclose(in);
sqlite3_finalize(pStmt);
Rf_error("RS_sqlite_import: %s line %d expected %d columns of data but found %d",
zFile, lineno, nCol, i + 1);
}
Expand All @@ -120,13 +125,18 @@ RS_sqlite_import(

rc = sqlite3_step(pStmt);
if (rc != SQLITE_DONE && rc != SQLITE_SCHEMA) {
free(zLine);
free(azCol);
fclose(in);
sqlite3_finalize(pStmt);
Rf_error("RS_sqlite_import: %s", sqlite3_errmsg(db));
}
rc = sqlite3_reset(pStmt);
free(zLine);
zLine = NULL;
if (rc != SQLITE_OK) {
free(azCol);
fclose(in);
sqlite3_finalize(pStmt);
Rf_error("RS_sqlite_import: %s", sqlite3_errmsg(db));
}
Expand Down
3 changes: 2 additions & 1 deletion src/vendor/extensions/regexp.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,8 @@ static const char *re_subcompile_string(ReCompiled *p){
** regular expression. Applications should invoke this routine once
** for every call to re_compile() to avoid memory leaks.
*/
static void re_free(ReCompiled *pRe){
static void re_free(void *pRe_){
ReCompiled *pRe = (ReCompiled*)pRe_;
if( pRe ){
sqlite3_free(pRe->aOp);
sqlite3_free(pRe->aArg);
Expand Down

0 comments on commit db32888

Please sign in to comment.