commit 530b872: [Minor] Simplify legacy calls via glib

Vsevolod Stakhov vsevolod at rspamd.com
Sun Oct 30 21:56:03 UTC 2022


Author: Vsevolod Stakhov
Date: 2022-10-30 21:53:15 +0000
URL: https://github.com/rspamd/rspamd/commit/530b8720f80ba89836e137b3096571e54226a8a0 (HEAD -> master)

[Minor] Simplify legacy calls via glib

---
 src/libserver/cfg_rcl.c | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)

diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c
index 7ae4bcbdc..01c2a6ad1 100644
--- a/src/libserver/cfg_rcl.c
+++ b/src/libserver/cfg_rcl.c
@@ -810,14 +810,12 @@ rspamd_rcl_lua_handler (rspamd_mempool_t *pool, const ucl_object_t *obj,
 	struct rspamd_config *cfg = ud;
 	const gchar *lua_src = rspamd_mempool_strdup (pool,
 			ucl_object_tostring (obj));
-	gchar *cur_dir, *lua_dir, *lua_file, *tmp1, *tmp2;
+	gchar *cur_dir, *lua_dir, *lua_file;
 	lua_State *L = cfg->lua_state;
 	gint err_idx;
 
-	tmp1 = g_strdup (lua_src);
-	tmp2 = g_strdup (lua_src);
-	lua_dir = dirname (tmp1);
-	lua_file = basename (tmp2);
+	lua_dir = g_path_get_dirname(lua_src);
+	lua_file = g_path_get_basename(lua_src);
 
 	if (lua_dir && lua_file) {
 		cur_dir = g_malloc (PATH_MAX);
@@ -839,8 +837,8 @@ rspamd_rcl_lua_handler (rspamd_mempool_t *pool, const ucl_object_t *obj,
 						strerror (errno));
 				}
 				g_free (cur_dir);
-				g_free (tmp1);
-				g_free (tmp2);
+				g_free (lua_dir);
+				g_free (lua_file);
 				return FALSE;
 			}
 
@@ -860,8 +858,8 @@ rspamd_rcl_lua_handler (rspamd_mempool_t *pool, const ucl_object_t *obj,
 				}
 
 				g_free (cur_dir);
-				g_free (tmp1);
-				g_free (tmp2);
+				g_free (lua_file);
+				g_free (lua_dir);
 
 				return FALSE;
 			}
@@ -875,8 +873,8 @@ rspamd_rcl_lua_handler (rspamd_mempool_t *pool, const ucl_object_t *obj,
 				msg_err_config ("cannot chdir to %s: %s", cur_dir, strerror (errno));
 			}
 			g_free (cur_dir);
-			g_free (tmp1);
-			g_free (tmp2);
+			g_free (lua_dir);
+			g_free (lua_file);
 			return FALSE;
 
 		}
@@ -884,12 +882,12 @@ rspamd_rcl_lua_handler (rspamd_mempool_t *pool, const ucl_object_t *obj,
 			msg_err_config ("cannot chdir to %s: %s", cur_dir, strerror (errno));
 		}
 		g_free (cur_dir);
-		g_free (tmp1);
-		g_free (tmp2);
+		g_free (lua_dir);
+		g_free (lua_file);
 	}
 	else {
-		g_free (tmp1);
-		g_free (tmp2);
+		g_free (lua_dir);
+		g_free (lua_file);
 		g_set_error (err, CFG_RCL_ERROR, ENOENT, "cannot find to %s: %s",
 			lua_src, strerror (errno));
 		return FALSE;


More information about the Commits mailing list