commit 275685d
Merge pull request 'Fixed more memory leaks in new features' (#584) from dandelions/snac2:pr-leaks-1 into master Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/584
2 files changed,
+21,
-9
M
html.c
+13,
-5
1@@ -645,12 +645,13 @@ xs_list *recipient_list(snac *snac, const xs_dict *msg, int expand_public)
2
3 while (xs_list_iter(&l, &v)) {
4 if (expand_public) {
5+ xs *followers_url = xs_fmt("%s/followers", snac->actor);
6 if (strcmp(v, public_address) == 0 ||
7 /* check if it's a followers collection URL */
8 (xs_type(v) == XSTYPE_STRING &&
9- strcmp(v, xs_fmt("%s/followers", snac->actor)) == 0) ||
10+ strcmp(v, followers_url) == 0) ||
11 (xs_type(v) == XSTYPE_LIST &&
12- xs_list_in(v, xs_fmt("%s/followers", snac->actor)) != -1)) {
13+ xs_list_in(v, followers_url) != -1)) {
14 /* iterate the followers and add them */
15 xs *fwers = follower_list(snac);
16 const char *actor;
17@@ -1624,6 +1625,7 @@ xs_dict *msg_emoji_init(snac *snac, const char *mid, const char *eid_o)
18 else if (*eid == '%') {
19 content = xs_url_dec_emoji(xs_dup(eid));
20 if (content == NULL) {
21+ xs_free(n_msg);
22 return NULL;
23 }
24 }
25@@ -1631,8 +1633,10 @@ xs_dict *msg_emoji_init(snac *snac, const char *mid, const char *eid_o)
26 content = xs_fmt(":%s:", eid);
27 const char *emo = xs_dict_get(emjs, content);
28
29- if (emo == NULL)
30+ if (emo == NULL) {
31+ xs_free(n_msg);
32 return NULL;
33+ }
34
35 if (xs_match(emo, "https://*|http://*")) { /* emoji is an URL to an image */
36 icon = xs_dict_set(icon, "type", "Image");
37@@ -1667,9 +1671,10 @@ xs_dict *msg_emoji_init(snac *snac, const char *mid, const char *eid_o)
38
39 accounts = xs_list_append(accounts, snac->actor);
40
41+ xs *to_duplicate = xs_dup(xs_list_get(xs_dict_get(n_msg, "to"), 1));
42 n_msg = xs_dict_set(n_msg, "content", content);
43 n_msg = xs_dict_set(n_msg, "accounts", accounts);
44- n_msg = xs_dict_set(n_msg, "attributedTo", xs_list_get(xs_dict_get(n_msg, "to"), 1));
45+ n_msg = xs_dict_set(n_msg, "attributedTo", to_duplicate);
46 n_msg = xs_dict_set(n_msg, "accountId", snac->uid);
47 n_msg = xs_dict_set(n_msg, "tag", tag);
48
49@@ -1679,6 +1684,7 @@ xs_dict *msg_emoji_init(snac *snac, const char *mid, const char *eid_o)
50 return n_msg;
51 }
52
53+ xs_free(n_msg);
54 return NULL;
55 }
56
57@@ -1710,13 +1716,14 @@ xs_dict *msg_emoji_unreact(snac *user, const char *mid, const char *eid)
58 if (strlen(eid) == 12 && *eid == '%') {
59 eid = xs_url_dec(eid);
60 if (eid == NULL) {
61+ xs_free(msg);
62 return NULL;
63 }
64 }
65
66 /* lets get all emotes for this msg, and compare it to our content */
67 while (xs_list_next(emotes, &v, &c)) {
68- xs_dict *e = NULL;
69+ xs *e = NULL;
70 if (valid_status(object_get_by_md5(v, &e))) {
71 const char *content = xs_dict_get(e, "content");
72 const char *id = xs_dict_get(e, "id");
73@@ -1730,6 +1737,7 @@ xs_dict *msg_emoji_unreact(snac *user, const char *mid, const char *eid)
74 }
75 }
76
77+ xs_free(msg);
78 return NULL;
79 }
80
M
html.c
+8,
-4
1@@ -4112,7 +4112,7 @@ void notify_filter(snac *user, const xs_dict *p_vars)
2 int folreq_on = (v = xs_dict_get(p_vars, "folreqs_on")) ? strcmp(v, "on") == 0 : 0;
3 int blocks_on = (v = xs_dict_get(p_vars, "blocks_on")) ? strcmp(v, "on") == 0 : 0;
4 int polls_on = (v = xs_dict_get(p_vars, "polls_on")) ? strcmp(v, "on") == 0 : 0;
5- xs_dict *filter = xs_dict_new();
6+ xs *filter = xs_dict_new();
7 filter = xs_dict_set(filter, "likes", xs_stock(likes_on ? XSTYPE_TRUE : XSTYPE_FALSE));
8 filter = xs_dict_set(filter, "reacts", xs_stock(reacts_on ? XSTYPE_TRUE : XSTYPE_FALSE));
9 filter = xs_dict_set(filter, "mentions", xs_stock(ments_on ? XSTYPE_TRUE : XSTYPE_FALSE));
10@@ -4123,6 +4123,7 @@ void notify_filter(snac *user, const xs_dict *p_vars)
11 filter = xs_dict_set(filter, "blocks", xs_stock(blocks_on ? XSTYPE_TRUE : XSTYPE_FALSE));
12 filter = xs_dict_set(filter, "polls", xs_stock(polls_on ? XSTYPE_TRUE : XSTYPE_FALSE));
13 user->config = xs_dict_set(user->config, "notify_filter", filter);
14+ user->tz = xs_dict_get_def(user->config, "tz", "UTC"); // previous line invalidates user->tz
15 }
16
17 xs_str *html_notifications(snac *user, int skip, int show)
18@@ -4138,7 +4139,9 @@ xs_str *html_notifications(snac *user, int skip, int show)
19 xs_html *body = html_user_body(user, 0);
20 const xs_dict *n_filter = xs_dict_get(user->config, "notify_filter");
21 if (!n_filter) {
22- user->config = xs_dict_set(user->config, "notify_filter", xs_dict_new());
23+ xs *filter = xs_dict_new();
24+ user->config = xs_dict_set(user->config, "notify_filter", filter);
25+ user->tz = xs_dict_get_def(user->config, "tz", "UTC"); // previous line invalidates user->tz
26 n_filter = xs_dict_get(user->config, "notify_filter");
27 }
28 xs *n_list = notify_filter_list(user, n_list_unfilt);
29@@ -4159,6 +4162,7 @@ xs_str *html_notifications(snac *user, int skip, int show)
30 body);
31
32 xs *filter_notifs_action = xs_fmt("%s/admin/filter-notifications", user->actor);
33+ xs *notifs_action = xs_fmt("%s/notifications", user->actor);
34 xs_html *notifs_form = xs_html_tag("form",
35 xs_html_attr("autocomplete", "off"),
36 xs_html_attr("method", "post"),
37@@ -4168,7 +4172,7 @@ xs_str *html_notifications(snac *user, int skip, int show)
38 xs_html_sctag("input",
39 xs_html_attr("type", "hidden"),
40 xs_html_attr("name", "hard-redir"),
41- xs_html_attr("value", xs_fmt("%s/notifications", user->actor))),
42+ xs_html_attr("value", notifs_action)),
43 html_checkbox("likes_on", L("Likes"), n_likes_on),
44 html_checkbox("reacts_on", L("Emoji reacts"), n_reacts_on),
45 html_checkbox("mentions_on", L("Mentions"), n_ments_on),
46@@ -5569,7 +5573,7 @@ int html_post_handler(const xs_dict *req, const char *q_path,
47
48 eid = xs_strip_chars_i(eid, ":");
49
50- const xs_dict *ret = msg_emoji_init(&snac, id, eid);
51+ xs *ret = msg_emoji_init(&snac, id, eid);
52 /* fails if either invalid or already reacted */
53 if (!ret)
54 ret = msg_emoji_unreact(&snac, id, eid);