Some code moving to avoid false positive leaks.

This commit is contained in:
default 2022-10-25 13:59:15 +02:00
parent 641d46cb3d
commit 78b3a30447
5 changed files with 39 additions and 23 deletions

View file

@ -123,7 +123,7 @@ int send_to_inbox(snac *snac, char *inbox, char *msg, d_char **payload, int *p_s
response = http_signed_request(snac, "POST", inbox, response = http_signed_request(snac, "POST", inbox,
NULL, j_msg, strlen(j_msg), &status, payload, p_size); NULL, j_msg, strlen(j_msg), &status, payload, p_size);
free(response); xs_free(response);
return status; return status;
} }
@ -553,7 +553,7 @@ d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to, char
/* if this message is public, ours will also be */ /* if this message is public, ours will also be */
if (is_msg_public(snac, p_msg) && if (is_msg_public(snac, p_msg) &&
xs_list_in(to, (char *)public_address) == -1) xs_list_in(to, public_address) == -1)
to = xs_list_append(to, public_address); to = xs_list_append(to, public_address);
} }

6
data.c
View file

@ -526,10 +526,10 @@ void _timeline_write(snac *snac, char *id, char *msg, char *parent, char *referr
fclose(f); fclose(f);
xs *g_msg = xs_json_loads(j); xs *g_msg = xs_json_loads(j);
d_char *meta = xs_dict_get(g_msg, "_snac"); char *meta = xs_dict_get(g_msg, "_snac");
d_char *p = xs_dict_get(meta, "parent"); char *p = xs_dict_get(meta, "parent");
free(grampa); xs_free(grampa);
grampa = xs_dup(p); grampa = xs_dup(p);
} }
} }

13
httpd.c
View file

@ -183,10 +183,8 @@ void httpd_connection(FILE *f)
b_size = strlen(body); b_size = strlen(body);
/* if it was a HEAD, no body will be sent */ /* if it was a HEAD, no body will be sent */
if (strcmp(method, "HEAD") == 0) { if (strcmp(method, "HEAD") == 0)
free(body); body = xs_free(body);
body = NULL;
}
xs_httpd_response(f, status, headers, body, b_size); xs_httpd_response(f, status, headers, body, b_size);
@ -194,7 +192,7 @@ void httpd_connection(FILE *f)
srv_archive("RECV", req, payload, p_size, status, headers, body, b_size); srv_archive("RECV", req, payload, p_size, status, headers, body, b_size);
free(body); xs_free(body);
} }
@ -233,9 +231,11 @@ static void *queue_thread(void *arg)
srv_log(xs_fmt("queue thread start")); srv_log(xs_fmt("queue thread start"));
while (srv_running) { while (srv_running) {
time_t t;
{
xs *list = user_list(); xs *list = user_list();
char *p, *uid; char *p, *uid;
time_t t;
/* process queues for all users */ /* process queues for all users */
p = list; p = list;
@ -247,6 +247,7 @@ static void *queue_thread(void *arg)
user_free(&snac); user_free(&snac);
} }
} }
}
/* time to purge? */ /* time to purge? */
if ((t = time(NULL)) > purge_time) { if ((t = time(NULL)) > purge_time) {

21
xs.h
View file

@ -66,7 +66,7 @@ d_char *xs_list_append_m(d_char *list, const char *mem, int dsz);
int xs_list_iter(char **list, char **value); int xs_list_iter(char **list, char **value);
int xs_list_len(char *list); int xs_list_len(char *list);
char *xs_list_get(char *list, int num); char *xs_list_get(char *list, int num);
int xs_list_in(char *list, char *val); int xs_list_in(char *list, const char *val);
d_char *xs_join(char *list, const char *sep); d_char *xs_join(char *list, const char *sep);
d_char *xs_split_n(const char *str, const char *sep, int times); d_char *xs_split_n(const char *str, const char *sep, int times);
#define xs_split(str, sep) xs_split_n(str, sep, 0xfffffff) #define xs_split(str, sep) xs_split_n(str, sep, 0xfffffff)
@ -96,12 +96,27 @@ void *_xs_realloc(void *ptr, size_t size, const char *file, int line, const char
#ifdef XS_DEBUG #ifdef XS_DEBUG
if (ndata != ptr) { if (ndata != ptr) {
int n;
FILE *f = fopen("xs_memory.out", "a"); FILE *f = fopen("xs_memory.out", "a");
if (ptr != NULL) if (ptr != NULL)
fprintf(f, "%p r\n", ptr); fprintf(f, "%p r\n", ptr);
fprintf(f, "%p a %ld %s %d %s\n", ndata, size, file, line, func); fprintf(f, "%p a %ld %s:%d: %s", ndata, size, file, line, func);
if (ptr != NULL) {
fprintf(f, " [");
for (n = 0; n < 32 && ndata[n]; n++) {
if (ndata[n] >= 32 && ndata[n] <= 127)
fprintf(f, "%c", ndata[n]);
else
fprintf(f, "\\%02x", (unsigned char)ndata[n]);
}
fprintf(f, "]");
}
fprintf(f, "\n");
fclose(f); fclose(f);
} }
#endif #endif
@ -531,7 +546,7 @@ char *xs_list_get(char *list, int num)
} }
int xs_list_in(char *list, char *val) int xs_list_in(char *list, const char *val)
/* returns the position of val in list or -1 */ /* returns the position of val in list or -1 */
{ {
int n = 0; int n = 0;

View file

@ -1 +1 @@
/* 286f556255aa224a72b778c44b837b75170becf5 */ /* 870b15e48a153ac601046ac2dc72dd8ccb0c77a4 */