aboutsummaryrefslogtreecommitdiffstats
path: root/epan/wslua/wslua_gui.c
diff options
context:
space:
mode:
authorMoshe Kaplan <me@moshekaplan.com>2020-12-20 21:30:28 -0500
committerAndersBroman <a.broman58@gmail.com>2020-12-22 14:56:38 +0000
commite16166a74cca1d66e2c302e257cf94aebb380599 (patch)
tree8834b4b8390fca83dd7bc1b4b9e6a7bb276e1d7e /epan/wslua/wslua_gui.c
parent7b27b444cbd94853b399da770e0dad4b91ef23ac (diff)
Detect and replace bad allocation patterns
Adds a pre-commit hook for detecting and replacing occurrences of `g_malloc()` and `wmem_alloc()` with `g_new()` and `wmem_new()`, to improve the readability of Wireshark's code, and occurrences of `g_malloc(sizeof(struct myobj) * foo)` with `g_new(struct myobj, foo)` to prevent integer overflows Also fixes all existing occurrences across the codebase.
Diffstat (limited to 'epan/wslua/wslua_gui.c')
-rw-r--r--epan/wslua/wslua_gui.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/epan/wslua/wslua_gui.c b/epan/wslua/wslua_gui.c
index 5dd45f753e..984848d79c 100644
--- a/epan/wslua/wslua_gui.c
+++ b/epan/wslua/wslua_gui.c
@@ -98,7 +98,7 @@ WSLUA_FUNCTION wslua_register_menu(lua_State* L) { /* Register a menu item in o
return 0;
}
- md = (struct _lua_menu_data *)g_malloc(sizeof(struct _lua_menu_data));
+ md = g_new(struct _lua_menu_data, 1);
md->L = L;
lua_pushvalue(L, 2);
@@ -277,7 +277,7 @@ WSLUA_FUNCTION wslua_new_dialog(lua_State* L) { /*
}
- dcbd = (struct _dlg_cb_data *)g_malloc(sizeof(struct _dlg_cb_data));
+ dcbd = g_new(struct _dlg_cb_data, 1);
dcbd->L = L;
lua_remove(L,1);
@@ -565,11 +565,11 @@ WSLUA_CONSTRUCTOR TextWindow_new(lua_State* L) { /*
}
title = luaL_optstring(L,WSLUA_OPTARG_TextWindow_new_TITLE, "Untitled Window");
- tw = (struct _wslua_tw *)g_malloc(sizeof(struct _wslua_tw));
+ tw = g_new(struct _wslua_tw, 1);
tw->expired = FALSE;
tw->ws_tw = ops->new_text_window(title);
- default_cbd = (struct _close_cb_data *)g_malloc(sizeof(struct _close_cb_data));
+ default_cbd = g_new(struct _close_cb_data, 1);
default_cbd->L = NULL;
default_cbd->func_ref = 0;
@@ -602,7 +602,7 @@ WSLUA_METHOD TextWindow_set_atclose(lua_State* L) { /* Set the function that wil
return 0;
}
- cbd = (struct _close_cb_data *)g_malloc(sizeof(struct _close_cb_data));
+ cbd = g_new(struct _close_cb_data, 1);
cbd->L = L;
cbd->func_ref = luaL_ref(L, LUA_REGISTRYINDEX);
@@ -804,8 +804,8 @@ WSLUA_METHOD TextWindow_add_button(lua_State* L) {
lua_settop(L,3);
if (ops->add_button) {
- fbt = (funnel_bt_t *)g_malloc(sizeof(funnel_bt_t));
- cbd = (wslua_bt_cb_t *)g_malloc(sizeof(wslua_bt_cb_t));
+ fbt = g_new(funnel_bt_t, 1);
+ cbd = g_new(wslua_bt_cb_t, 1);
fbt->tw = tw->ws_tw;
fbt->func = wslua_button_callback;