1
0
mirror of https://github.com/irssi/irssi.git synced 2024-11-03 04:27:19 -05:00

added destroy() function to WI_ITEM_REC. This fixes a potential crash when

"window item destroy" signal was being used.


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1655 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2001-07-26 01:49:08 +00:00 committed by cras
parent 219d276b0a
commit 3fb7a4115d
7 changed files with 29 additions and 59 deletions

View File

@ -48,6 +48,7 @@ void channel_init(CHANNEL_REC *channel, int automatic)
MODULE_DATA_INIT(channel); MODULE_DATA_INIT(channel);
channel->type = module_get_uniq_id_str("WINDOW ITEM TYPE", "CHANNEL"); channel->type = module_get_uniq_id_str("WINDOW ITEM TYPE", "CHANNEL");
channel->destroy = (void (*) (WI_ITEM_REC *)) channel_destroy;
channel->mode = g_strdup(""); channel->mode = g_strdup("");
channel->createtime = time(NULL); channel->createtime = time(NULL);
channel->get_join_data = get_join_data; channel->get_join_data = get_join_data;

View File

@ -36,6 +36,7 @@ void query_init(QUERY_REC *query, int automatic)
MODULE_DATA_INIT(query); MODULE_DATA_INIT(query);
query->type = module_get_uniq_id_str("WINDOW ITEM TYPE", "QUERY"); query->type = module_get_uniq_id_str("WINDOW ITEM TYPE", "QUERY");
query->destroy = (void (*) (WI_ITEM_REC *)) query_destroy;
if (query->server_tag != NULL) { if (query->server_tag != NULL) {
query->server = server_find_tag(query->server_tag); query->server = server_find_tag(query->server_tag);
if (query->server != NULL) { if (query->server != NULL) {

View File

@ -12,4 +12,6 @@ time_t createtime;
int data_level; int data_level;
char *hilight_color; char *hilight_color;
void (*destroy)(WI_ITEM_REC *item);
#undef STRUCT_SERVER_REC #undef STRUCT_SERVER_REC

View File

@ -74,16 +74,6 @@ static void signal_channel_destroyed(CHANNEL_REC *channel)
window_auto_destroy(window); window_auto_destroy(window);
} }
static void signal_window_item_destroy(WINDOW_REC *window, WI_ITEM_REC *item)
{
CHANNEL_REC *channel;
g_return_if_fail(window != NULL);
channel = CHANNEL(item);
if (channel != NULL) channel_destroy(channel);
}
static void sig_disconnected(SERVER_REC *server) static void sig_disconnected(SERVER_REC *server)
{ {
WINDOW_REC *window; WINDOW_REC *window;
@ -576,7 +566,6 @@ void fe_channels_init(void)
signal_add("channel created", (SIGNAL_FUNC) signal_channel_created); signal_add("channel created", (SIGNAL_FUNC) signal_channel_created);
signal_add("channel destroyed", (SIGNAL_FUNC) signal_channel_destroyed); signal_add("channel destroyed", (SIGNAL_FUNC) signal_channel_destroyed);
signal_add_last("window item destroy", (SIGNAL_FUNC) signal_window_item_destroy);
signal_add_last("window item changed", (SIGNAL_FUNC) signal_window_item_changed); signal_add_last("window item changed", (SIGNAL_FUNC) signal_window_item_changed);
signal_add_last("server disconnected", (SIGNAL_FUNC) sig_disconnected); signal_add_last("server disconnected", (SIGNAL_FUNC) sig_disconnected);
@ -599,7 +588,6 @@ void fe_channels_deinit(void)
{ {
signal_remove("channel created", (SIGNAL_FUNC) signal_channel_created); signal_remove("channel created", (SIGNAL_FUNC) signal_channel_created);
signal_remove("channel destroyed", (SIGNAL_FUNC) signal_channel_destroyed); signal_remove("channel destroyed", (SIGNAL_FUNC) signal_channel_destroyed);
signal_remove("window item destroy", (SIGNAL_FUNC) signal_window_item_destroy);
signal_remove("window item changed", (SIGNAL_FUNC) signal_window_item_changed); signal_remove("window item changed", (SIGNAL_FUNC) signal_window_item_changed);
signal_remove("server disconnected", (SIGNAL_FUNC) sig_disconnected); signal_remove("server disconnected", (SIGNAL_FUNC) sig_disconnected);

View File

@ -38,28 +38,6 @@
static GSList *processes; static GSList *processes;
static int signal_exec_input; static int signal_exec_input;
static EXEC_WI_REC *exec_wi_create(WINDOW_REC *window, PROCESS_REC *rec)
{
EXEC_WI_REC *item;
g_return_val_if_fail(window != NULL, NULL);
g_return_val_if_fail(rec != NULL, NULL);
item = g_new0(EXEC_WI_REC, 1);
item->type = module_get_uniq_id_str("WINDOW ITEM TYPE", "EXEC");
item->name = rec->name != NULL ?
g_strdup_printf("%%%s", rec->name) :
g_strdup_printf("%%%d", rec->id);
item->window = window;
item->createtime = time(NULL);
item->process = rec;
MODULE_DATA_INIT(item);
window_item_add(window, (WI_ITEM_REC *) item, FALSE);
return item;
}
static void exec_wi_destroy(EXEC_WI_REC *rec) static void exec_wi_destroy(EXEC_WI_REC *rec)
{ {
g_return_if_fail(rec != NULL); g_return_if_fail(rec != NULL);
@ -75,6 +53,29 @@ static void exec_wi_destroy(EXEC_WI_REC *rec)
g_free(rec); g_free(rec);
} }
static EXEC_WI_REC *exec_wi_create(WINDOW_REC *window, PROCESS_REC *rec)
{
EXEC_WI_REC *item;
g_return_val_if_fail(window != NULL, NULL);
g_return_val_if_fail(rec != NULL, NULL);
item = g_new0(EXEC_WI_REC, 1);
item->type = module_get_uniq_id_str("WINDOW ITEM TYPE", "EXEC");
item->destroy = (void (*) (WI_ITEM_REC *)) exec_wi_destroy;
item->name = rec->name != NULL ?
g_strdup_printf("%%%s", rec->name) :
g_strdup_printf("%%%d", rec->id);
item->window = window;
item->createtime = time(NULL);
item->process = rec;
MODULE_DATA_INIT(item);
window_item_add(window, (WI_ITEM_REC *) item, FALSE);
return item;
}
static int process_get_new_id(void) static int process_get_new_id(void)
{ {
PROCESS_REC *rec; PROCESS_REC *rec;
@ -590,14 +591,6 @@ static void sig_window_destroyed(WINDOW_REC *window)
} }
} }
static void sig_window_item_destroyed(WINDOW_REC *window, EXEC_WI_REC *item)
{
if (IS_EXEC_WI(item)) {
item->process->target_item = NULL;
exec_wi_destroy(item);
}
}
static void event_text(const char *data, SERVER_REC *server, EXEC_WI_REC *item) static void event_text(const char *data, SERVER_REC *server, EXEC_WI_REC *item)
{ {
if (!IS_EXEC_WI(item)) return; if (!IS_EXEC_WI(item)) return;
@ -616,7 +609,6 @@ void fe_exec_init(void)
signal_add("pidwait", (SIGNAL_FUNC) sig_pidwait); signal_add("pidwait", (SIGNAL_FUNC) sig_pidwait);
signal_add("exec input", (SIGNAL_FUNC) sig_exec_input); signal_add("exec input", (SIGNAL_FUNC) sig_exec_input);
signal_add("window destroyed", (SIGNAL_FUNC) sig_window_destroyed); signal_add("window destroyed", (SIGNAL_FUNC) sig_window_destroyed);
signal_add("window item destroy", (SIGNAL_FUNC) sig_window_item_destroyed);
signal_add_first("send text", (SIGNAL_FUNC) event_text); signal_add_first("send text", (SIGNAL_FUNC) event_text);
} }
@ -636,6 +628,5 @@ void fe_exec_deinit(void)
signal_remove("pidwait", (SIGNAL_FUNC) sig_pidwait); signal_remove("pidwait", (SIGNAL_FUNC) sig_pidwait);
signal_remove("exec input", (SIGNAL_FUNC) sig_exec_input); signal_remove("exec input", (SIGNAL_FUNC) sig_exec_input);
signal_remove("window destroyed", (SIGNAL_FUNC) sig_window_destroyed); signal_remove("window destroyed", (SIGNAL_FUNC) sig_window_destroyed);
signal_remove("window item destroy", (SIGNAL_FUNC) sig_window_item_destroyed);
signal_remove("send text", (SIGNAL_FUNC) event_text); signal_remove("send text", (SIGNAL_FUNC) event_text);
} }

View File

@ -120,16 +120,6 @@ static void signal_window_item_server_changed(WINDOW_REC *window,
} }
} }
static void signal_window_item_destroy(WINDOW_REC *window, WI_ITEM_REC *item)
{
QUERY_REC *query;
g_return_if_fail(window != NULL);
query = QUERY(item);
if (query != NULL) query_destroy(query);
}
static void sig_server_connected(SERVER_REC *server) static void sig_server_connected(SERVER_REC *server)
{ {
GSList *tmp; GSList *tmp;
@ -349,7 +339,6 @@ void fe_queries_init(void)
signal_add("query server changed", (SIGNAL_FUNC) signal_query_server_changed); signal_add("query server changed", (SIGNAL_FUNC) signal_query_server_changed);
signal_add("query nick changed", (SIGNAL_FUNC) signal_query_nick_changed); signal_add("query nick changed", (SIGNAL_FUNC) signal_query_nick_changed);
signal_add("window item server changed", (SIGNAL_FUNC) signal_window_item_server_changed); signal_add("window item server changed", (SIGNAL_FUNC) signal_window_item_server_changed);
signal_add_last("window item destroy", (SIGNAL_FUNC) signal_window_item_destroy);
signal_add("server connected", (SIGNAL_FUNC) sig_server_connected); signal_add("server connected", (SIGNAL_FUNC) sig_server_connected);
signal_add("window changed", (SIGNAL_FUNC) sig_window_changed); signal_add("window changed", (SIGNAL_FUNC) sig_window_changed);
signal_add_first("message private", (SIGNAL_FUNC) sig_message_private); signal_add_first("message private", (SIGNAL_FUNC) sig_message_private);
@ -371,7 +360,6 @@ void fe_queries_deinit(void)
signal_remove("query server changed", (SIGNAL_FUNC) signal_query_server_changed); signal_remove("query server changed", (SIGNAL_FUNC) signal_query_server_changed);
signal_remove("query nick changed", (SIGNAL_FUNC) signal_query_nick_changed); signal_remove("query nick changed", (SIGNAL_FUNC) signal_query_nick_changed);
signal_remove("window item server changed", (SIGNAL_FUNC) signal_window_item_server_changed); signal_remove("window item server changed", (SIGNAL_FUNC) signal_window_item_server_changed);
signal_remove("window item destroy", (SIGNAL_FUNC) signal_window_item_destroy);
signal_remove("server connected", (SIGNAL_FUNC) sig_server_connected); signal_remove("server connected", (SIGNAL_FUNC) sig_server_connected);
signal_remove("window changed", (SIGNAL_FUNC) sig_window_changed); signal_remove("window changed", (SIGNAL_FUNC) sig_window_changed);
signal_remove("message private", (SIGNAL_FUNC) sig_message_private); signal_remove("message private", (SIGNAL_FUNC) sig_message_private);

View File

@ -66,7 +66,7 @@ void window_item_remove(WI_ITEM_REC *item)
window = window_item_window(item); window = window_item_window(item);
if (g_slist_find(window->items, item) == NULL) if (window == NULL)
return; return;
item->window = NULL; item->window = NULL;
@ -86,8 +86,7 @@ void window_item_destroy(WI_ITEM_REC *item)
window = window_item_window(item); window = window_item_window(item);
window_item_remove(item); window_item_remove(item);
item->destroy(item);
signal_emit("window item destroy", 2, window, item);
} }
void window_item_change_server(WI_ITEM_REC *item, void *server) void window_item_change_server(WI_ITEM_REC *item, void *server)