From 788b35535f7fce3cb75c6b4a77ff571e6e0e5c3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sat, 30 Nov 2024 20:02:15 +0100 Subject: [PATCH 1/4] fix: Fix valgrind error --- src/import-file.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/import-file.c b/src/import-file.c index e26cbf5f8..34d2b1b8d 100644 --- a/src/import-file.c +++ b/src/import-file.c @@ -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; @@ -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); } @@ -120,6 +125,9 @@ 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)); } @@ -127,6 +135,8 @@ RS_sqlite_import( free(zLine); zLine = NULL; if (rc != SQLITE_OK) { + free(azCol); + fclose(in); sqlite3_finalize(pStmt); Rf_error("RS_sqlite_import: %s", sqlite3_errmsg(db)); } From 3a9012f07d9f7da290809d89549b663a75fd4e6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sat, 30 Nov 2024 20:04:14 +0100 Subject: [PATCH 2/4] 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 182664932..340357eaf 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); From a5d356ed8e64adac8f63c1f889f99effd8e25f75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sat, 30 Nov 2024 20:07:45 +0100 Subject: [PATCH 3/4] Add patch --- data-raw/upgrade.R | 5 +++++ patch/0001-Function-pointer-safety.patch | 26 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 patch/0001-Function-pointer-safety.patch diff --git a/data-raw/upgrade.R b/data-raw/upgrade.R index b02b256ef..e13d48ba9 100644 --- a/data-raw/upgrade.R +++ b/data-raw/upgrade.R @@ -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") diff --git a/patch/0001-Function-pointer-safety.patch b/patch/0001-Function-pointer-safety.patch new file mode 100644 index 000000000..fbcd62ca0 --- /dev/null +++ b/patch/0001-Function-pointer-safety.patch @@ -0,0 +1,26 @@ +From 3a9012f07d9f7da290809d89549b663a75fd4e6b Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Kirill=20M=C3=BCller?= +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 + From a3fefe864cbf1ea11912ed7e6407c4d805e91f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sat, 30 Nov 2024 20:17:23 +0100 Subject: [PATCH 4/4] Build-ignore --- .Rbuildignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.Rbuildignore b/.Rbuildignore index b31ad646d..6c4465baf 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -41,3 +41,4 @@ a.out.dSYM ^\.gitpod\.yml$ ^src/CMakeLists\.txt$ ^\.aviator/config\.yml$ +^patch$