rspamd_cryptobox_fast_hash_state_t crc_st;
guint64 crc;
rspamd_regexp_t *re;
- hs_compile_error_t *hs_errors;
+ hs_compile_error_t *hs_errors = NULL;
guint *hs_flags = NULL;
const hs_expr_ext_t **hs_exts = NULL;
gchar **hs_pats = NULL;
/* Adjust real re number */
n = i;
+#define CLEANUP_ALLOCATED(is_err) do { \
+ g_free (hs_flags); \
+ g_free (hs_ids); \
+ for (guint j = 0; j < i; j ++) { \
+ g_free (hs_pats[j]); \
+ } \
+ g_free (hs_pats); \
+ g_free (hs_exts); \
+ if (is_err) { \
+ close (fd); \
+ unlink (path); \
+ if (hs_errors) hs_free_compile_error (hs_errors); \
+ } \
+} while(0)
+
if (n > 0) {
/* Create the hs tree */
+ hs_errors = NULL;
if (hs_compile_ext_multi ((const char **)hs_pats,
hs_flags,
hs_ids,
&test_db,
&hs_errors) != HS_SUCCESS) {
-
- g_free (hs_flags);
- g_free (hs_ids);
-
- for (guint j = 0; j < i; j ++) {
- g_free (hs_pats[j]);
- }
-
err = g_error_new (rspamd_re_cache_quark (), EINVAL,
"cannot create tree of regexp when processing '%s': %s",
hs_pats[hs_errors->expression], hs_errors->message);
- g_free (hs_pats);
- g_free (hs_exts);
- close (fd);
- unlink (path);
- hs_free_compile_error (hs_errors);
-
+ CLEANUP_ALLOCATED(true);
rspamd_re_cache_compile_err (EV_A_ w, err, cbdata, false);
return;
}
- for (guint j = 0; j < i; j ++) {
- g_free (hs_pats[j]);
- }
-
- g_free (hs_pats);
- g_free (hs_exts);
-
if (hs_serialize_database (test_db, &hs_serialized,
&serialized_len) != HS_SUCCESS) {
err = g_error_new (rspamd_re_cache_quark (),
"cannot serialize tree of regexp for %s",
re_class->hash);
- close (fd);
- unlink (path);
- g_free (hs_ids);
- g_free (hs_flags);
+ CLEANUP_ALLOCATED(true);
hs_free_database (test_db);
-
rspamd_re_cache_compile_err (EV_A_ w, err, cbdata, false);
return;
}
errno,
"cannot serialize tree of regexp to %s: %s",
path, strerror (errno));
- close (fd);
- unlink (path);
- g_free (hs_ids);
- g_free (hs_flags);
+
+ CLEANUP_ALLOCATED(true);
g_free (hs_serialized);
rspamd_re_cache_compile_err (EV_A_ w, err, cbdata, false);
}
cbdata->total += n;
-
- g_free (hs_serialized);
- g_free (hs_ids);
- g_free (hs_flags);
+ CLEANUP_ALLOCATED(false);
/* Now rename temporary file to the new .hs file */
rspamd_snprintf (npath, sizeof (npath), "%s%c%s.hs", cbdata->cache_dir,
(gint)g_hash_table_size (re_class->re),
path);
- g_free (hs_serialized);
- g_free (hs_ids);
- g_free (hs_flags);
- unlink (path);
- close (fd);
+ CLEANUP_ALLOCATED(true);
rspamd_re_cache_compile_err (EV_A_ w, err, cbdata, false);
return;