1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
From eef971c3aeb61b9b60013f3b728f62e7ac5580bf Mon Sep 17 00:00:00 2001
From: Stefan Becker <chemobejk@gmail.com>
Date: Wed, 10 Apr 2013 13:13:04 +0000
Subject: request: fix resource leakage
It is the responsibility of the UI code to free the "fields" parameter
after haze_request_fields() has been called. This has to be done with
purple_request_close() and handled in the close_request() UI operation.
https://bugs.freedesktop.org/show_bug.cgi?id=63326
---
diff --git a/src/request.c b/src/request.c
index dae859d..db54317 100644
--- a/src/request.c
+++ b/src/request.c
@@ -101,7 +101,7 @@ haze_request_action (const char *title,
}
#endif
-struct password_data {
+struct fields_data {
PurpleRequestFields *fields;
PurpleRequestField *password;
GCallback ok_cb;
@@ -109,21 +109,40 @@ struct password_data {
void *user_data;
};
+static void haze_close_request(PurpleRequestType type, void *ui_handle)
+{
+ struct fields_data *fd = ui_handle;
+
+ purple_request_fields_destroy(fd->fields);
+ g_free(fd);
+}
+
void haze_request_password_cb (gpointer user_data,
const gchar *password)
{
- struct password_data *pd = user_data;
+ struct fields_data *fd = user_data;
if (password) {
- purple_request_field_string_set_value(pd->password, password);
- ((PurpleRequestFieldsCb)pd->ok_cb)(pd->user_data, pd->fields);
+ purple_request_field_string_set_value(fd->password, password);
+ ((PurpleRequestFieldsCb)fd->ok_cb)(fd->user_data, fd->fields);
} else {
- ((PurpleRequestFieldsCb)pd->cancel_cb)(pd->user_data, pd->fields);
+ ((PurpleRequestFieldsCb)fd->cancel_cb)(fd->user_data, fd->fields);
}
- g_free(pd);
+ purple_request_close(PURPLE_REQUEST_FIELDS, fd);
}
+static gboolean haze_request_fields_destroy(gpointer user_data)
+{
+ purple_request_close(PURPLE_REQUEST_FIELDS, user_data);
+ return FALSE;
+}
+
+/*
+ * We must support purple_account_request_password() which boils down
+ * to purple_request_fields() with certain parameters. I'm not sure
+ * if this the best way of doing this, but it works.
+ */
static gpointer
haze_request_fields (const char *title,
const char *primary,
@@ -138,33 +157,34 @@ haze_request_fields (const char *title,
PurpleConversation *conv,
void *user_data)
{
- /*
- * We must support purple_account_request_password() which boils down
- * to purple_request_fields() with certain parameters. I'm not sure
- * if this the best way of doing this, but it works.
- */
+ struct fields_data *fd = g_new0(struct fields_data, 1);
+
+ /* it is our responsibility to destroy this data */
+ fd->fields = fields;
+
if (purple_request_fields_exists(fields, "password") &&
purple_request_fields_exists(fields, "remember")) {
- struct password_data *pd = g_new0(struct password_data, 1);
DEBUG ("triggering password request");
- pd->fields = fields;
- pd->password = purple_request_fields_get_field(fields, "password");
- pd->ok_cb = ok_cb;
- pd->cancel_cb = cancel_cb;
- pd->user_data = user_data;
+ fd->password = purple_request_fields_get_field(fields, "password");
+ fd->ok_cb = ok_cb;
+ fd->cancel_cb = cancel_cb;
+ fd->user_data = user_data;
- haze_connection_request_password(account, pd);
+ haze_connection_request_password(account, fd);
} else {
DEBUG ("ignoring request:");
DEBUG (" title: %s", (title ? title : "(null)"));
DEBUG (" primary: %s", (primary ? primary : "(null)"));
DEBUG (" secondary: %s", (secondary ? secondary : "(null)"));
+
+ /* Avoid leaking of "fields" */
+ g_idle_add(haze_request_fields_destroy, fd);
}
- return NULL;
+ return fd;
}
#ifdef ENABLE_LEAKY_REQUEST_STUBS
@@ -204,10 +224,6 @@ haze_request_folder (const char *title,
}
#endif
-/*
- void (*close_request)(PurpleRequestType type, void *ui_handle);
-*/
-
static PurpleRequestUiOps request_uiops =
{
#ifdef ENABLE_LEAKY_REQUEST_STUBS
@@ -217,7 +233,8 @@ static PurpleRequestUiOps request_uiops =
.request_file = haze_request_file,
.request_folder = haze_request_folder,
#endif
- .request_fields = haze_request_fields
+ .request_fields = haze_request_fields,
+ .close_request = haze_close_request
};
PurpleRequestUiOps *
--
cgit v0.9.0.2-2-gbebe
|