links

lynx-like text mode web browser
git clone anongit@rnpnr.xyz:links.git
Log | Files | Refs | Feed | README | LICENSE

Commit: 7dfcbddb8a9060e5320602782071b55e28580800
Parent: bfaf36b3b5b0390d327e17a6eaed50bdb22fe3ba
Author: opask
Date:   Sun, 22 Jul 2018 20:38:00 -0600

remove mem_free from menu.c, objreq.c, os_dep.c, and sched.c

Diffstat:
Mmenu.c | 57+++++++++++++++++++++++++++++----------------------------
Mobjreq.c | 44++++++++++++++++++++++----------------------
Mos_dep.c | 7++++---
Msched.c | 81++++++++++++++++++++++++++++++++++++-------------------------------------------
4 files changed, 92 insertions(+), 97 deletions(-)

diff --git a/menu.c b/menu.c @@ -139,10 +139,9 @@ static void menu_version(void *term_) if (links_home) { unsigned char *native_home = os_conv_to_external_path(links_home, NULL); add_to_str(&s, &l, native_home); - mem_free(native_home); - } else { + free(native_home); + } else add_to_str(&s, &l, get_text_translation(TEXT_(T_NONE), term)); - } add_to_str(&s, &l, cast_uchar "\n"); s[l - 1] = 0; @@ -280,7 +279,7 @@ static void refresh(void *r_) static void end_refresh(struct refresh *r) { if (r->timer != NULL) kill_timer(r->timer); - mem_free(r); + free(r); } static void refresh_abort(struct dialog_data *dlg) @@ -421,8 +420,8 @@ static int resource_info(struct terminal *term, struct refresh *r2) add_to_str(&a, &l, cast_uchar "."); if (r2 && !strcmp(cast_const_char a, cast_const_char *(unsigned char **)((struct dialog_data *)r2->win->data)->dlg->udata)) { - mem_free(a); - mem_free(r); + free(a); + free(r); r2->timer = install_timer(RESOURCE_INFO_REFRESH, refresh, r2); return 1; } @@ -1335,8 +1334,8 @@ static void display_proxy(struct terminal *term, unsigned char *result, unsigned safe_strncpy(result, res + 8, MAX_STR_LEN); } - mem_free(url); - mem_free(res); + free(url); + free(res); } static void display_noproxy_list(struct terminal *term, unsigned char *result, unsigned char *noproxy_list) @@ -1345,10 +1344,9 @@ static void display_noproxy_list(struct terminal *term, unsigned char *result, u res = display_host_list(term, noproxy_list); if (!res) { result[0] = 0; - } else { + } else safe_strncpy(result, res, MAX_STR_LEN); - } - mem_free(res); + free(res); } int save_proxy(int charset, unsigned char *result, unsigned char *proxy) @@ -1368,17 +1366,17 @@ int save_proxy(int charset, unsigned char *result, unsigned char *proxy) add_to_strn(&url, proxy); add_to_strn(&url, cast_uchar "/"); - mem_free(proxy); + free(proxy); if (parse_url(url, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) { - mem_free(url); + free(url); result[0] = 0; return -1; } res = idn_encode_url(url, 0); - mem_free(url); + free(url); if (!res) { result[0] = 0; @@ -1394,7 +1392,7 @@ int save_proxy(int charset, unsigned char *result, unsigned char *proxy) retval = strlen(cast_const_char (res + 8)) >= MAX_STR_LEN ? -1 : 0; } - mem_free(res); + free(res); return retval; } @@ -1405,7 +1403,7 @@ int save_noproxy_list(int charset, unsigned char *result, unsigned char *noproxy noproxy_list = convert(charset, utf8_table, noproxy_list, NULL); res = idn_encode_host(noproxy_list, (int)strlen(cast_const_char noproxy_list), cast_uchar ".,", 0); - mem_free(noproxy_list); + free(noproxy_list); if (!res) { result[0] = 0; return -1; @@ -1413,7 +1411,7 @@ int save_noproxy_list(int charset, unsigned char *result, unsigned char *noproxy safe_strncpy(result, res, MAX_STR_LEN); retval = strlen(cast_const_char res) >= MAX_STR_LEN ? -1 : 0; } - mem_free(res); + free(res); return retval; } @@ -1421,11 +1419,11 @@ static int check_proxy_noproxy(struct dialog_data *dlg, struct dialog_item_data { unsigned char *result = xmalloc(MAX_STR_LEN); if (save(term_charset(dlg->win->term), result, di->cdata)) { - mem_free(result); + free(result); msg_box(dlg->win->term, NULL, TEXT_(T_BAD_STRING), AL_CENTER, TEXT_(T_BAD_PROXY_SYNTAX), MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC); return 1; } - mem_free(result); + free(result); return 0; } @@ -3331,15 +3329,18 @@ static void does_file_exist(void *d_, unsigned char *file) set_cwd(ses->term->cwd); f = translate_download_file(file); EINTRLOOP(r, stat(cast_const_char f, &st)); - mem_free(f); - if (wd) set_cwd(wd), mem_free(wd); + free(f); + if (wd) { + set_cwd(wd); + free(wd); + } if (r) { does_file_exist_ok(h, DOWNLOAD_DEFAULT); free_h_ret: - if (h->head) mem_free(h->head); - mem_free(h->file); - mem_free(h->url); - mem_free(h); + free(h->head); + free(h->file); + free(h->url); + free(h); return; } @@ -3415,14 +3416,14 @@ void query_file(struct session *ses, unsigned char *url, unsigned char *head, vo fc = get_filename_from_url(url, head, 0); file = convert(utf8_table, 0, fc, NULL); - mem_free(fc); + free(fc); check_filename(&file); def = init_str(); add_to_str(&def, &dfl, download_dir); if (*def && !dir_sep(def[strlen(cast_const_char def) - 1])) add_chr_to_str(&def, &dfl, '/'); add_to_str(&def, &dfl, file); - mem_free(file); + free(file); h->fn = fn; h->cancel = cancel; @@ -3433,7 +3434,7 @@ void query_file(struct session *ses, unsigned char *url, unsigned char *head, vo h->head = stracpy(head); input_field(ses->term, getml(h, h->url, h->head, NULL), TEXT_(T_DOWNLOAD), TEXT_(T_SAVE_TO_FILE), h, &file_history, MAX_INPUT_URL_LEN, def, 0, 0, NULL, 2, TEXT_(T_OK), does_file_exist, TEXT_(T_CANCEL), query_file_cancel); - mem_free(def); + free(def); } static struct history search_history = { 0, { &search_history.items, &search_history.items } }; diff --git a/objreq.c b/objreq.c @@ -105,8 +105,8 @@ static int auth_ok(struct dialog_data *dlg, struct dialog_item_data *item) uid = convert(term_charset(dlg->win->term), net_cp, a->uid, NULL); passwd = convert(term_charset(dlg->win->term), net_cp, a->passwd, NULL); add_auth(rq->url, a->realm, uid, passwd, a->proxy); - mem_free(uid); - mem_free(passwd); + free(uid); + free(passwd); rq->hold = 0; change_connection(&rq->stat, NULL, PRI_CANCEL); load_url(rq->url, rq->prev_url, &rq->stat, rq->pri, NC_RELOAD, 0, 0, 0); @@ -135,11 +135,11 @@ static int auth_window(struct object_request *rq, unsigned char *realm) unsigned char *h = get_host_name(rq->url); if (!h) return -1; host = display_host(term, h); - mem_free(h); + free(h); if ((port = get_port_str(rq->url))) { add_to_strn(&host, cast_uchar ":"); add_to_strn(&host, port); - mem_free(port); + free(port); } } urealm = convert(term_charset(term), net_cp, realm, NULL); @@ -153,8 +153,8 @@ static int auth_window(struct object_request *rq, unsigned char *realm) strcat(cast_char a->msg, cast_const_char get_text_translation(TEXT_(T_AT), term)); strcat(cast_char a->msg, cast_const_char host); } - mem_free(host); - mem_free(urealm); + free(host); + free(urealm); a->proxy = rq->ce_internal->http_code == 407; a->realm = stracpy(realm); a->count = rq->count; @@ -214,7 +214,7 @@ static void cert_forall(struct cert_dialog *cs, int yes) foreach(struct object_request, rq, lrq, requests) if (rq->term == cs->term && rq->hold == HOLD_CERT && rq->stat.state == cs->state) { unsigned char *host = get_host_name(rq->url); if (!strcmp(cast_const_char host, cast_const_char cs->host)) cert_action(rq, yes); - mem_free(host); + free(host); } } @@ -292,7 +292,7 @@ void request_object(struct terminal *term, unsigned char *url, unsigned char *pr rq->data = data; rq->timer = NULL; rq->last_update = get_time() - STAT_UPDATE_MAX; - if (rq->prev_url) mem_free(rq->prev_url); + free(rq->prev_url); rq->prev_url = stracpy(prev_url); if (rqp) *rqp = rq; rq->count = obj_req_count++; @@ -336,14 +336,14 @@ static void objreq_end(struct status *stat, void *data) change_connection(stat, NULL, PRI_CANCEL); u = join_urls(rq->url, stat->ce->redirect); if ((pos = extract_position(u))) { - if (rq->goto_position) mem_free(rq->goto_position); + free(rq->goto_position); rq->goto_position = pos; } if (!http_options.bug_302_redirect && !stat->ce->redirect_get && (p = cast_uchar strchr(cast_const_char u, POST_CHAR))) add_to_strn(&u, p); cache = rq->cache; if (cache < NC_RELOAD && (!strcmp(cast_const_char u, cast_const_char rq->url) || !strcmp(cast_const_char u, cast_const_char rq->orig_url) || rq->redirect_cnt >= MAX_CACHED_REDIRECTS)) cache = NC_RELOAD; allow_flags = get_allow_flags(rq->url); - mem_free(rq->url); + free(rq->url); rq->url = u; load_url(u, rq->prev_url, &rq->stat, rq->pri, cache, 0, allow_flags, 0); return; @@ -357,26 +357,26 @@ static void objreq_end(struct status *stat, void *data) unsigned char *user; if (!realm) goto xx; if (stat->ce->http_code == 401 && !find_auth(rq->url, realm)) { - mem_free(realm); + free(realm); if (rq->redirect_cnt++ >= MAX_REDIRECTS) goto maxrd; change_connection(stat, NULL, PRI_CANCEL); load_url(rq->url, rq->prev_url, &rq->stat, rq->pri, NC_RELOAD, 0, 0, 0); return; } user = get_user_name(rq->url); - if (stat->ce->http_code == 401 && user && *user) { - mem_free(user); - mem_free(realm); + if (stat->ce->http_code == 401 && *user) { + free(user); + free(realm); goto xx; } - mem_free(user); + free(user); if (!auth_window(rq, realm)) { rq->hold = HOLD_AUTH; rq->redirect_cnt = 0; - mem_free(realm); + free(realm); goto tm; } - mem_free(realm); + free(realm); goto xx; } } @@ -435,12 +435,12 @@ void release_object_get_stat(struct object_request **rqq, struct status *news, i if (rq->timer != NULL) kill_timer(rq->timer); if (rq->ce_internal) rq->ce_internal->refcount--; if (rq->ce) rq->ce->refcount--; - mem_free(rq->orig_url); - mem_free(rq->url); - if (rq->prev_url) mem_free(rq->prev_url); - if (rq->goto_position) mem_free(rq->goto_position); + free(rq->orig_url); + free(rq->url); + free(rq->prev_url); + free(rq->goto_position); del_from_list(rq); - mem_free(rq); + free(rq); } void release_object(struct object_request **rqq) diff --git a/os_dep.c b/os_dep.c @@ -152,7 +152,8 @@ static unsigned char *clipboard = NULL; void os_free_clipboard(void) { - if (clipboard) mem_free(clipboard), clipboard = NULL; + free(clipboard); + clipboard = NULL; } /* Terminal size */ @@ -503,7 +504,7 @@ void set_clipboard_text(struct terminal *term, unsigned char *data) return; } #endif - if (clipboard) mem_free(clipboard); + free(clipboard); clipboard = convert(term_charset(term), utf8_table, data, NULL); } @@ -748,7 +749,7 @@ static void exec_new_links(struct terminal *term, unsigned char *xterm, unsigned add_to_strn(&str, cast_uchar " "); add_to_strn(&str, param); exec_on_terminal(term, str, cast_uchar "", 2); - mem_free(str); + free(str); } static int open_in_new_twterm(struct terminal *term, unsigned char *exe, unsigned char *param) diff --git a/sched.c b/sched.c @@ -81,10 +81,10 @@ static struct h_conn *is_host_on_list(struct connection *c) struct list_head *lh; if (!(ho = get_host_name(c->url))) return NULL; foreach(struct h_conn, h, lh, h_conns) if (!strcmp(cast_const_char h->host, cast_const_char ho)) { - mem_free(ho); + free(ho); return h; } - mem_free(ho); + free(ho); return NULL; } @@ -163,10 +163,10 @@ static struct k_conn *is_host_on_keepalive_list(struct connection *c) if (!(ho = get_keepalive_id(c->url))) return NULL; foreach(struct k_conn, h, lh, keepalive_connections) if (h->protocol == ph && h->port == po && !strcmp(cast_const_char h->host, cast_const_char ho)) { - mem_free(ho); + free(ho); return h; } - mem_free(ho); + free(ho); return NULL; } @@ -182,8 +182,8 @@ int get_keepalive_socket(struct connection *c, int *protocol_data) c->ssl = k->ssl; memcpy(&c->last_lookup_state, &k->last_lookup_state, sizeof(struct lookup_state)); del_from_list(k); - mem_free(k->host); - mem_free(k); + free(k->host); + free(k); c->sock1 = cc; if (max_tries == 1) c->tries = -1; return 0; @@ -213,18 +213,12 @@ static void free_connection_data(struct connection *c) } c->running = 0; if (c->dnsquery) kill_dns_request(&c->dnsquery); - if (c->buffer) { - mem_free(c->buffer); - c->buffer = NULL; - } - if (c->newconn) { - mem_free(c->newconn); - c->newconn = NULL; - } - if (c->info) { - mem_free(c->info); - c->info = NULL; - } + free(c->buffer); + free(c->newconn); + free(c->info); + c->buffer = NULL; + c->newconn = NULL; + c->info = NULL; clear_connection_timeout(c); if (--active_connections < 0) { internal("active connections underflow"); @@ -234,8 +228,8 @@ static void free_connection_data(struct connection *c) if ((h = is_host_on_list(c))) { if (!--h->conn) { del_from_list(h); - mem_free(h->host); - mem_free(h); + free(h->host); + free(h); } } else internal("suspending connection that is not on the list (state %d)", c->state); } @@ -289,13 +283,12 @@ static void del_connection(struct connection *c) if (c->detached) { if (ce && !ce->url[0] && !is_entry_used(ce) && !ce->refcount) delete_cache_entry(ce); - } else { + } else if (ce) trim_cache_entry(ce); - } - mem_free(c->url); - if (c->prev_url) mem_free(c->prev_url); - mem_free(c); + free(c->url); + free(c->prev_url); + free(c); } void add_keepalive_socket(struct connection *c, uttime timeout, int protocol_data) @@ -313,7 +306,7 @@ void add_keepalive_socket(struct connection *c, uttime timeout, int protocol_dat (k->port = get_port(c->url)) == -1 || !(k->protocol = get_protocol_handle(c->url)) || !(k->host = get_keepalive_id(c->url))) { - mem_free(k); + free(k); del_connection(c); goto clos; } @@ -341,8 +334,8 @@ static void del_keepalive_socket(struct k_conn *kc) del_from_list(kc); freeSSL(kc->ssl); EINTRLOOP(rs, close(kc->conn)); - mem_free(kc->host); - mem_free(kc); + free(kc->host); + free(kc); } static struct timer *keepalive_timeout = NULL; @@ -431,10 +424,10 @@ static int try_to_suspend_connection(struct connection *c, unsigned char *ho) unsigned char *h; if (!(h = get_host_name(d->url))) continue; if (strcmp(cast_const_char h, cast_const_char ho)) { - mem_free(h); + free(h); continue; } - mem_free(h); + free(h); } suspend_connection(d); return 0; @@ -456,7 +449,7 @@ static int is_noproxy_url(unsigned char *url) goto no_match; if (casecmp(np, host + (host_l - l), l)) goto no_match; - mem_free(host); + free(host); return 1; no_match: if (!np[l]) @@ -464,7 +457,7 @@ no_match: np += l + 1; } } - mem_free(host); + free(host); return 0; } @@ -503,7 +496,7 @@ static void run_connection(struct connection *c) if (!(hc = is_host_on_list(c))) { hc = xmalloc(sizeof(struct h_conn)); if (!(hc->host = get_host_name(c->url))) { - mem_free(hc); + free(hc); goto s_bad_url; } hc->conn = 0; @@ -522,21 +515,21 @@ static int is_connection_seekable(struct connection *c) !casestrcmp(protocol, cast_uchar "https") || !casestrcmp(protocol, cast_uchar "proxy")) { unsigned char *d; - mem_free(protocol); + free(protocol); if (!c->cache || !c->cache->head) return 1; d = parse_http_header(c->cache->head, cast_uchar "Accept-Ranges", NULL); if (d) { - mem_free(d); + free(d); return 1; } return 0; } if (!casestrcmp(protocol, cast_uchar "ftp")) { - mem_free(protocol); + free(protocol); return 1; } - mem_free(protocol); + free(protocol); return 0; } @@ -791,7 +784,7 @@ void load_url(unsigned char *url, unsigned char *prev_url, struct status *stat, unsigned char *enc; enc = parse_http_header(e->head, cast_uchar "Content-Encoding", NULL); if (enc) { - mem_free(enc); + free(enc); e->refcount--; must_detach = 1; goto skip_cache; @@ -824,12 +817,12 @@ void load_url(unsigned char *url, unsigned char *prev_url, struct status *stat, } enc = parse_http_header(c->cache->head, cast_uchar "Content-Encoding", NULL); if (enc) { - mem_free(enc); + free(enc); must_detach = 1; break; } } - mem_free(u); + free(u); if (getpri(c) > pri) { del_from_list(c); c->pri[pri]++; @@ -885,9 +878,9 @@ void load_url(unsigned char *url, unsigned char *prev_url, struct status *stat, c->timer = NULL; if (position || must_detach) { if (new_cache_entry(cast_uchar "", &c->cache)) { - mem_free(c->url); - if (c->prev_url) mem_free(c->prev_url); - mem_free(c); + free(c->url); + free(c->prev_url); + free(c); if (stat) { stat->state = S_OUT_OF_MEM; if (stat->end) stat->end(stat, stat->data); @@ -1100,7 +1093,7 @@ void del_blacklist_entry(unsigned char *host, int flags) b->flags &= ~flags; if (!b->flags) { del_from_list(b); - mem_free(b); + free(b); } return; }