commit b13a396: [Minor] One more mkstemp usage

Vsevolod Stakhov vsevolod at rspamd.com
Sat Mar 4 13:49:04 UTC 2023


Author: Vsevolod Stakhov
Date: 2023-03-04 13:41:58 +0000
URL: https://github.com/rspamd/rspamd/commit/b13a39610c9007a1afa4d1dbf94d73a1a5b1269b (HEAD -> master)

[Minor] One more mkstemp usage

---
 src/libserver/maps/map_helpers.c | 7 +++----
 src/libserver/re_cache.c         | 8 ++++----
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/libserver/maps/map_helpers.c b/src/libserver/maps/map_helpers.c
index 2fa7743b4..a1052326c 100644
--- a/src/libserver/maps/map_helpers.c
+++ b/src/libserver/maps/map_helpers.c
@@ -1093,11 +1093,10 @@ rspamd_try_save_re_map_cache (struct rspamd_regexp_map_helper *re_map)
 		return FALSE;
 	}
 
-	rspamd_snprintf (fp, sizeof (fp), "%s/%*xs.hsmc.tmp",
-			re_map->map->cfg->hs_cache_dir,
-			(gint)rspamd_cryptobox_HASHBYTES / 2, re_map->re_digest);
+	rspamd_snprintf (fp, sizeof (fp), "%s/hsmc-XXXXXXXXXXXXX",
+			re_map->map->cfg->hs_cache_dir);
 
-	if ((fd = rspamd_file_xopen (fp, O_WRONLY | O_CREAT | O_EXCL, 00644, 0)) != -1) {
+	if ((fd = g_mkstemp_full(fp, O_WRONLY | O_CREAT | O_EXCL, 00644)) != -1) {
 		if (hs_serialize_database (rspamd_hyperscan_get_database(re_map->hs_db), &bytes, &len) == HS_SUCCESS) {
 			if (write (fd, bytes, len) == -1) {
 				msg_warn_map ("cannot write hyperscan cache to %s: %s",
diff --git a/src/libserver/re_cache.c b/src/libserver/re_cache.c
index c89536206..cbf76d1a9 100644
--- a/src/libserver/re_cache.c
+++ b/src/libserver/re_cache.c
@@ -1954,10 +1954,10 @@ rspamd_re_cache_compile_timer_cb (EV_P_ ev_timer *w, int revents )
 
 	g_hash_table_iter_init (&cit, re_class->re);
 	n = g_hash_table_size (re_class->re);
-	hs_flags = g_malloc0 (sizeof (*hs_flags) * n);
-	hs_ids = g_malloc (sizeof (*hs_ids) * n);
-	hs_pats = g_malloc (sizeof (*hs_pats) * n);
-	hs_exts = g_malloc0 (sizeof (*hs_exts) * n);
+	hs_flags = g_new0(guint, n);
+	hs_ids = g_new0(guint, n);
+	hs_pats = g_new0(char *, n);
+	hs_exts = g_new0(const hs_expr_ext_t *, n);
 	i = 0;
 
 	while (g_hash_table_iter_next (&cit, &k, &v)) {


More information about the Commits mailing list