1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

Replaced xfree_null() by xfree() and nullify argument after freeing.

This commit is contained in:
Tim Ruehsen 2014-11-29 17:54:20 +01:00 committed by Tim Rühsen
parent d9325f5db5
commit 4850e9c873
23 changed files with 176 additions and 200 deletions

View File

@ -1,3 +1,12 @@
2014-11-29 Tim Ruehsen <tim.ruehsen@gmx.de>
* utils.h: xfree() sets argument to NULL after freeing,
removed xfree_null()
* connect.c, cookies.c, ftp-basic.c, ftp-ls.c, ftp.c hash.c,
host.c, html-url.c, http.c, init.c, iri.c, log.c, main.c,
mswindows.c, netrc.c, openssl.c, recur.c, res.c, retr.c,
url.c, warc.c: Replaced xfree_null() by xfree()
2014-11-28 Tim Ruehsen <tim.ruehsen@gmx.de> 2014-11-28 Tim Ruehsen <tim.ruehsen@gmx.de>
* main.c: Fix length of program_argstring, * main.c: Fix length of program_argstring,

View File

@ -284,7 +284,6 @@ connect_to_ip (const ip_address *ip, int port, const char *print)
logprintf (LOG_VERBOSE, _("Connecting to %s|%s|:%d... "), logprintf (LOG_VERBOSE, _("Connecting to %s|%s|:%d... "),
str ? str : escnonprint_uri (print), txt_addr, port); str ? str : escnonprint_uri (print), txt_addr, port);
if (str)
xfree (str); xfree (str);
} }
else else

View File

@ -153,10 +153,10 @@ cookie_expired_p (const struct cookie *c)
static void static void
delete_cookie (struct cookie *cookie) delete_cookie (struct cookie *cookie)
{ {
xfree_null (cookie->domain); xfree (cookie->domain);
xfree_null (cookie->path); xfree (cookie->path);
xfree_null (cookie->attr); xfree (cookie->attr);
xfree_null (cookie->value); xfree (cookie->value);
xfree (cookie); xfree (cookie);
} }
@ -376,7 +376,7 @@ parse_set_cookie (const char *set_cookie, bool silent)
{ {
if (!TOKEN_NON_EMPTY (value)) if (!TOKEN_NON_EMPTY (value))
goto error; goto error;
xfree_null (cookie->domain); xfree (cookie->domain);
/* Strictly speaking, we should set cookie->domain_exact if the /* Strictly speaking, we should set cookie->domain_exact if the
domain doesn't begin with a dot. But many sites set the domain doesn't begin with a dot. But many sites set the
domain to "foo.com" and expect "subhost.foo.com" to get the domain to "foo.com" and expect "subhost.foo.com" to get the
@ -389,7 +389,7 @@ parse_set_cookie (const char *set_cookie, bool silent)
{ {
if (!TOKEN_NON_EMPTY (value)) if (!TOKEN_NON_EMPTY (value))
goto error; goto error;
xfree_null (cookie->path); xfree (cookie->path);
cookie->path = strdupdelim (value.b, value.e); cookie->path = strdupdelim (value.b, value.e);
} }
else if (TOKEN_IS (name, "expires")) else if (TOKEN_IS (name, "expires"))

View File

@ -1136,7 +1136,7 @@ ftp_pwd (int csock, char **pwd)
goto err; goto err;
/* Has the `pwd' been already allocated? Free! */ /* Has the `pwd' been already allocated? Free! */
xfree_null (*pwd); xfree (*pwd);
*pwd = xstrdup (request); *pwd = xstrdup (request);

View File

@ -363,8 +363,8 @@ ftp_parse_unix_ls (const char *file, int ignore_perms)
if (error || ignore) if (error || ignore)
{ {
DEBUGP (("Skipping.\n")); DEBUGP (("Skipping.\n"));
xfree_null (cur.name); xfree (cur.name);
xfree_null (cur.linkto); xfree (cur.linkto);
continue; continue;
} }
@ -1089,7 +1089,7 @@ ftp_index (const char *file, struct url *u, struct fileinfo *f)
else else
upwd = concat_strings (tmpu, "@", (char *) 0); upwd = concat_strings (tmpu, "@", (char *) 0);
xfree (tmpu); xfree (tmpu);
xfree_null (tmpp); xfree (tmpp);
} }
else else
upwd = xstrdup (""); upwd = xstrdup ("");

View File

@ -449,7 +449,7 @@ Error in server response, closing control connection.\n"));
return err; return err;
case FTPSRVERR : case FTPSRVERR :
/* PWD unsupported -- assume "/". */ /* PWD unsupported -- assume "/". */
xfree_null (con->id); xfree (con->id);
con->id = xstrdup ("/"); con->id = xstrdup ("/");
break; break;
case FTPOK: case FTPOK:
@ -1703,7 +1703,7 @@ ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con, char **local_fi
if (err == FOPEN_EXCL_ERR) if (err == FOPEN_EXCL_ERR)
{ {
/* Re-determine the file name. */ /* Re-determine the file name. */
xfree_null (con->target); xfree (con->target);
con->target = url_file_name (u, NULL); con->target = url_file_name (u, NULL);
locf = con->target; locf = con->target;
} }
@ -2473,10 +2473,8 @@ ftp_loop (struct url *u, char **local_file, int *dt, struct url *proxy,
/* If a connection was left, quench it. */ /* If a connection was left, quench it. */
if (con.csock != -1) if (con.csock != -1)
fd_close (con.csock); fd_close (con.csock);
xfree_null (con.id); xfree (con.id);
con.id = NULL; xfree (con.target);
xfree_null (con.target);
con.target = NULL;
return res; return res;
} }
@ -2490,7 +2488,7 @@ delelement (struct fileinfo *f, struct fileinfo **start)
struct fileinfo *next = f->next; struct fileinfo *next = f->next;
xfree (f->name); xfree (f->name);
xfree_null (f->linkto); xfree (f->linkto);
xfree (f); xfree (f);
if (next) if (next)

View File

@ -46,10 +46,11 @@ as that of the covered work. */
# include "utils.h" # include "utils.h"
#else #else
/* Make do without them. */ /* Make do without them. */
# define xnew(x) xmalloc (sizeof (x)) # define xnew(type) (xmalloc (sizeof (type)))
# define xnew_array(type, x) xmalloc (sizeof (type) * (x)) # define xnew0(type) (xcalloc (1, sizeof (type)))
# define xmalloc malloc # define xnew_array(type, len) (xmalloc ((len) * sizeof (type)))
# define xfree free # define xfree(p) do { free ((void *) (p)); p = NULL; } while (0)
# ifndef countof # ifndef countof
# define countof(x) (sizeof (x) / sizeof ((x)[0])) # define countof(x) (sizeof (x) / sizeof ((x)[0]))
# endif # endif

View File

@ -747,7 +747,6 @@ lookup_host (const char *host, int flags)
logprintf (LOG_VERBOSE, _("Resolving %s... "), logprintf (LOG_VERBOSE, _("Resolving %s... "),
quotearg_style (escape_quoting_style, str ? str : host)); quotearg_style (escape_quoting_style, str ? str : host));
if (str)
xfree (str); xfree (str);
} }

View File

@ -488,7 +488,6 @@ tag_handle_base (int tagid _GL_UNUSED, struct taginfo *tag, struct map_context *
base_urlpos->ignore_when_downloading = 1; base_urlpos->ignore_when_downloading = 1;
base_urlpos->link_base_p = 1; base_urlpos->link_base_p = 1;
if (ctx->base)
xfree (ctx->base); xfree (ctx->base);
if (ctx->parent_base) if (ctx->parent_base)
ctx->base = uri_merge (ctx->parent_base, newbase); ctx->base = uri_merge (ctx->parent_base, newbase);
@ -630,7 +629,7 @@ tag_handle_meta (int tagid _GL_UNUSED, struct taginfo *tag, struct map_context *
if (!mcharset) if (!mcharset)
return; return;
xfree_null (meta_charset); xfree (meta_charset);
meta_charset = mcharset; meta_charset = mcharset;
} }
else if (name && 0 == c_strcasecmp (name, "robots")) else if (name && 0 == c_strcasecmp (name, "robots"))
@ -758,7 +757,7 @@ get_urls_html (const char *file, const char *url, bool *meta_disallow_follow,
if (meta_disallow_follow) if (meta_disallow_follow)
*meta_disallow_follow = ctx.nofollow; *meta_disallow_follow = ctx.nofollow;
xfree_null (ctx.base); xfree (ctx.base);
wget_read_file_free (fm); wget_read_file_free (fm);
return ctx.head; return ctx.head;
} }

View File

@ -236,7 +236,7 @@ request_set_header (struct request *req, const char *name, const char *value,
/* A NULL value is a no-op; if freeing the name is requested, /* A NULL value is a no-op; if freeing the name is requested,
free it now to avoid leaks. */ free it now to avoid leaks. */
if (release_policy == rel_name || release_policy == rel_both) if (release_policy == rel_name || release_policy == rel_both)
xfree ((void *)name); xfree (name);
return; return;
} }
@ -387,10 +387,10 @@ static void
request_free (struct request *req) request_free (struct request *req)
{ {
int i; int i;
xfree_null (req->arg); xfree (req->arg);
for (i = 0; i < req->hcount; i++) for (i = 0; i < req->hcount; i++)
release_header (&req->headers[i]); release_header (&req->headers[i]);
xfree_null (req->headers); xfree (req->headers);
xfree (req); xfree (req);
} }
@ -818,7 +818,7 @@ resp_status (const struct response *resp, char **message)
static void static void
resp_free (struct response *resp) resp_free (struct response *resp)
{ {
xfree_null (resp->headers); xfree (resp->headers);
xfree (resp); xfree (resp);
} }
@ -948,7 +948,7 @@ skip_short_body (int fd, wgint contlen, bool chunked)
if (remaining_chunk_size == 0) if (remaining_chunk_size == 0)
{ {
line = fd_read_line (fd); line = fd_read_line (fd);
xfree_null (line); xfree (line);
break; break;
} }
} }
@ -1475,18 +1475,13 @@ struct http_stat
static void static void
free_hstat (struct http_stat *hs) free_hstat (struct http_stat *hs)
{ {
xfree_null (hs->newloc); xfree (hs->newloc);
xfree_null (hs->remote_time); xfree (hs->remote_time);
xfree_null (hs->error); xfree (hs->error);
xfree_null (hs->rderrmsg); xfree (hs->rderrmsg);
xfree_null (hs->local_file); xfree (hs->local_file);
xfree_null (hs->orig_file_name); xfree (hs->orig_file_name);
xfree_null (hs->message); xfree (hs->message);
/* Guard against being called twice. */
hs->newloc = NULL;
hs->remote_time = NULL;
hs->error = NULL;
} }
static void static void
@ -1756,7 +1751,7 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy,
hs->res = -1; hs->res = -1;
hs->rderrmsg = NULL; hs->rderrmsg = NULL;
hs->newloc = NULL; hs->newloc = NULL;
xfree(hs->remote_time); hs->remote_time = NULL; xfree(hs->remote_time);
hs->error = NULL; hs->error = NULL;
hs->message = NULL; hs->message = NULL;
@ -2078,7 +2073,7 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy,
request_free (req); request_free (req);
return HERR; return HERR;
} }
xfree_null(hs->message); xfree(hs->message);
hs->message = xstrdup (message); hs->message = xstrdup (message);
resp_free (resp); resp_free (resp);
xfree (head); xfree (head);
@ -2087,11 +2082,11 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy,
failed_tunnel: failed_tunnel:
logprintf (LOG_NOTQUIET, _("Proxy tunneling failed: %s"), logprintf (LOG_NOTQUIET, _("Proxy tunneling failed: %s"),
message ? quotearg_style (escape_quoting_style, message) : "?"); message ? quotearg_style (escape_quoting_style, message) : "?");
xfree_null (message); xfree (message);
request_free (req); request_free (req);
return CONSSLERR; return CONSSLERR;
} }
xfree_null (message); xfree (message);
/* SOCK is now *really* connected to u->host, so update CONN /* SOCK is now *really* connected to u->host, so update CONN
to reflect this. That way register_persistent will to reflect this. That way register_persistent will
@ -2260,7 +2255,7 @@ read_header:
goto read_header; goto read_header;
} }
xfree_null(hs->message); xfree(hs->message);
hs->message = xstrdup (message); hs->message = xstrdup (message);
if (!opt.server_response) if (!opt.server_response)
logprintf (LOG_VERBOSE, "%2d %s\n", statcode, logprintf (LOG_VERBOSE, "%2d %s\n", statcode,
@ -2350,13 +2345,13 @@ read_header:
u->url, warc_timestamp_str, u->url, warc_timestamp_str,
warc_request_uuid, warc_ip, type, warc_request_uuid, warc_ip, type,
statcode, head); statcode, head);
xfree_null (type); xfree (type);
if (_err != RETRFINISHED || hs->res < 0) if (_err != RETRFINISHED || hs->res < 0)
{ {
CLOSE_INVALIDATE (sock); CLOSE_INVALIDATE (sock);
request_free (req); request_free (req);
xfree_null (message); xfree (message);
resp_free (resp); resp_free (resp);
xfree (head); xfree (head);
return _err; return _err;
@ -2477,12 +2472,11 @@ read_header:
} }
xfree (pth); xfree (pth);
xfree_null (message); xfree (message);
resp_free (resp); resp_free (resp);
xfree (head); xfree (head);
xfree (auth_stat); xfree (auth_stat);
xfree (hs->message); xfree (hs->message);
hs->message = NULL;
goto retry_with_auth; goto retry_with_auth;
} }
else else
@ -2497,7 +2491,7 @@ read_header:
} }
} }
request_free (req); request_free (req);
xfree_null (message); xfree (message);
resp_free (resp); resp_free (resp);
xfree (head); xfree (head);
if (auth_err == RETROK) if (auth_err == RETROK)
@ -2521,8 +2515,7 @@ read_header:
CLOSE_FINISH (sock); CLOSE_FINISH (sock);
request_free (req); request_free (req);
xfree (hs->message); xfree (hs->message);
hs->message = NULL; xfree (message);
xfree_null (message);
resp_free (resp); resp_free (resp);
xfree (head); xfree (head);
@ -2553,7 +2546,7 @@ read_header:
hs->local_file = url_file_name (u, local_file); hs->local_file = url_file_name (u, local_file);
} }
xfree_null (local_file); xfree (local_file);
} }
/* TODO: perform this check only once. */ /* TODO: perform this check only once. */
@ -2568,7 +2561,7 @@ read_header:
request_free (req); request_free (req);
resp_free (resp); resp_free (resp);
xfree (head); xfree (head);
xfree_null (message); xfree (message);
return RETRUNNEEDED; return RETRUNNEEDED;
} }
else if (!ALLOW_CLOBBER) else if (!ALLOW_CLOBBER)
@ -2651,7 +2644,7 @@ read_header:
hs->error = xstrdup (_("(no description)")); hs->error = xstrdup (_("(no description)"));
else else
hs->error = xstrdup (message); hs->error = xstrdup (message);
xfree_null (message); xfree (message);
type = resp_header_strdup (resp, "Content-Type"); type = resp_header_strdup (resp, "Content-Type");
if (type) if (type)
@ -2672,7 +2665,7 @@ read_header:
tmp = parse_charset (tmp2); tmp = parse_charset (tmp2);
if (tmp) if (tmp)
set_content_encoding (iri, tmp); set_content_encoding (iri, tmp);
xfree_null(tmp); xfree(tmp);
} }
} }
} }
@ -2705,7 +2698,7 @@ read_header:
hs->restval = 0; hs->restval = 0;
CLOSE_FINISH (sock); CLOSE_FINISH (sock);
xfree_null (type); xfree (type);
xfree (head); xfree (head);
return RETRFINISHED; return RETRFINISHED;
@ -2746,7 +2739,7 @@ read_header:
if (_err != RETRFINISHED || hs->res < 0) if (_err != RETRFINISHED || hs->res < 0)
{ {
CLOSE_INVALIDATE (sock); CLOSE_INVALIDATE (sock);
xfree_null (type); xfree (type);
xfree (head); xfree (head);
return _err; return _err;
} }
@ -2763,7 +2756,7 @@ read_header:
CLOSE_INVALIDATE (sock); CLOSE_INVALIDATE (sock);
} }
xfree_null (type); xfree (type);
xfree (head); xfree (head);
/* From RFC2616: The status codes 303 and 307 have /* From RFC2616: The status codes 303 and 307 have
been added for servers that wish to make unambiguously been added for servers that wish to make unambiguously
@ -2846,7 +2839,7 @@ read_header:
hs->res = 0; hs->res = 0;
/* Mark as successfully retrieved. */ /* Mark as successfully retrieved. */
*dt |= RETROKF; *dt |= RETROKF;
xfree_null (type); xfree (type);
if (statcode == HTTP_STATUS_RANGE_NOT_SATISFIABLE) if (statcode == HTTP_STATUS_RANGE_NOT_SATISFIABLE)
CLOSE_FINISH (sock); CLOSE_FINISH (sock);
else else
@ -2860,7 +2853,7 @@ read_header:
{ {
/* The Range request was somehow misunderstood by the server. /* The Range request was somehow misunderstood by the server.
Bail out. */ Bail out. */
xfree_null (type); xfree (type);
CLOSE_INVALIDATE (sock); CLOSE_INVALIDATE (sock);
xfree (head); xfree (head);
return RANGEERR; return RANGEERR;
@ -2927,7 +2920,7 @@ read_header:
{ {
CLOSE_INVALIDATE (sock); CLOSE_INVALIDATE (sock);
xfree (head); xfree (head);
xfree_null (type); xfree (type);
return _err; return _err;
} }
else else
@ -2952,7 +2945,7 @@ read_header:
} }
xfree (head); xfree (head);
xfree_null (type); xfree (type);
return RETRFINISHED; return RETRFINISHED;
} }
@ -2993,7 +2986,7 @@ read_header:
strerror (errno)); strerror (errno));
CLOSE_INVALIDATE (sock); CLOSE_INVALIDATE (sock);
xfree (head); xfree (head);
xfree_null (type); xfree (type);
return UNLINKERR; return UNLINKERR;
} }
} }
@ -3021,7 +3014,7 @@ read_header:
hs->local_file); hs->local_file);
CLOSE_INVALIDATE (sock); CLOSE_INVALIDATE (sock);
xfree (head); xfree (head);
xfree_null (type); xfree (type);
return FOPEN_EXCL_ERR; return FOPEN_EXCL_ERR;
} }
} }
@ -3030,7 +3023,7 @@ read_header:
logprintf (LOG_NOTQUIET, "%s: %s\n", hs->local_file, strerror (errno)); logprintf (LOG_NOTQUIET, "%s: %s\n", hs->local_file, strerror (errno));
CLOSE_INVALIDATE (sock); CLOSE_INVALIDATE (sock);
xfree (head); xfree (head);
xfree_null (type); xfree (type);
return FOPENERR; return FOPENERR;
} }
} }
@ -3050,7 +3043,7 @@ read_header:
/* Now we no longer need to store the response header. */ /* Now we no longer need to store the response header. */
xfree (head); xfree (head);
xfree_null (type); xfree (type);
if (hs->res >= 0) if (hs->res >= 0)
CLOSE_FINISH (sock); CLOSE_FINISH (sock);
@ -3370,7 +3363,7 @@ Remote file does not exist -- broken link!!!\n"));
} }
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
ret = WRONGCODE; ret = WRONGCODE;
xfree_null (hurl); xfree (hurl);
goto exit; goto exit;
} }
@ -3494,10 +3487,8 @@ Remote file exists.\n\n"));
got_name = true; got_name = true;
*dt &= ~HEAD_ONLY; *dt &= ~HEAD_ONLY;
count = 0; /* the retrieve count for HEAD is reset */ count = 0; /* the retrieve count for HEAD is reset */
xfree_null (hstat.message); xfree (hstat.message);
xfree_null (hstat.error); xfree (hstat.error);
hstat.message = NULL;
hstat.error = NULL;
continue; continue;
} /* send_head_first */ } /* send_head_first */
} /* !got_head */ } /* !got_head */
@ -3646,7 +3637,7 @@ Remote file exists.\n\n"));
exit: exit:
if (ret == RETROK && local_file) if (ret == RETROK && local_file)
{ {
xfree_null (*local_file); xfree (*local_file);
*local_file = xstrdup (hstat.local_file); *local_file = xstrdup (hstat.local_file);
} }
free_hstat (&hstat); free_hstat (&hstat);
@ -3866,23 +3857,21 @@ digest_authentication_encode (const char *au, const char *user,
if (qop != NULL && strcmp(qop,"auth")) if (qop != NULL && strcmp(qop,"auth"))
{ {
logprintf (LOG_NOTQUIET, _("Unsupported quality of protection '%s'.\n"), qop); logprintf (LOG_NOTQUIET, _("Unsupported quality of protection '%s'.\n"), qop);
xfree_null (qop); /* force freeing mem and return */ xfree (qop); /* force freeing mem and return */
qop = NULL;
} }
else if (algorithm != NULL && strcmp (algorithm,"MD5") && strcmp (algorithm,"MD5-sess")) else if (algorithm != NULL && strcmp (algorithm,"MD5") && strcmp (algorithm,"MD5-sess"))
{ {
logprintf (LOG_NOTQUIET, _("Unsupported algorithm '%s'.\n"), algorithm); logprintf (LOG_NOTQUIET, _("Unsupported algorithm '%s'.\n"), algorithm);
xfree_null (qop); /* force freeing mem and return */ xfree (qop); /* force freeing mem and return */
qop = NULL;
} }
if (!realm || !nonce || !user || !passwd || !path || !method || !qop) if (!realm || !nonce || !user || !passwd || !path || !method || !qop)
{ {
xfree_null (realm); xfree (realm);
xfree_null (opaque); xfree (opaque);
xfree_null (nonce); xfree (nonce);
xfree_null (qop); xfree (qop);
xfree_null (algorithm); xfree (algorithm);
if (!qop) if (!qop)
*auth_err = UNKNOWNATTR; *auth_err = UNKNOWNATTR;
else else
@ -4009,11 +3998,11 @@ digest_authentication_encode (const char *au, const char *user,
} }
} }
xfree_null (realm); xfree (realm);
xfree_null (opaque); xfree (opaque);
xfree_null (nonce); xfree (nonce);
xfree_null (qop); xfree (qop);
xfree_null (algorithm); xfree (algorithm);
return res; return res;
} }
@ -4108,7 +4097,7 @@ save_cookies (void)
void void
http_cleanup (void) http_cleanup (void)
{ {
xfree_null (pconn.host); xfree (pconn.host);
if (wget_cookie_jar) if (wget_cookie_jar)
cookie_jar_delete (wget_cookie_jar); cookie_jar_delete (wget_cookie_jar);
} }

View File

@ -527,7 +527,7 @@ wgetrc_user_file_name (void)
home = home_dir (); home = home_dir ();
if (home) if (home)
file = aprintf ("%s/.wgetrc", home); file = aprintf ("%s/.wgetrc", home);
xfree_null (home); xfree (home);
#endif /* def __VMS [else] */ #endif /* def __VMS [else] */
if (!file) if (!file)
@ -562,8 +562,7 @@ wgetrc_file_name (void)
if (!file) if (!file)
{ {
char *home = home_dir (); char *home = home_dir ();
xfree_null (file); xfree (file);
file = NULL;
home = ws_mypath (); home = ws_mypath ();
if (home) if (home)
{ {
@ -571,7 +570,6 @@ wgetrc_file_name (void)
if (!file_exists_p (file)) if (!file_exists_p (file))
{ {
xfree (file); xfree (file);
file = NULL;
} }
xfree (home); xfree (home);
} }
@ -645,8 +643,8 @@ run_wgetrc (const char *file)
default: default:
abort (); abort ();
} }
xfree_null (com); xfree (com);
xfree_null (val); xfree (val);
++ln; ++ln;
} }
xfree (line); xfree (line);
@ -982,7 +980,7 @@ cmd_string (const char *com _GL_UNUSED, const char *val, void *place)
{ {
char **pstring = (char **)place; char **pstring = (char **)place;
xfree_null (*pstring); xfree (*pstring);
*pstring = xstrdup (val); *pstring = xstrdup (val);
return true; return true;
} }
@ -993,7 +991,7 @@ cmd_string_uppercase (const char *com _GL_UNUSED, const char *val, void *place)
{ {
char *q, **pstring; char *q, **pstring;
pstring = (char **)place; pstring = (char **)place;
xfree_null (*pstring); xfree (*pstring);
*pstring = xmalloc (strlen (val) + 1); *pstring = xmalloc (strlen (val) + 1);
@ -1013,7 +1011,7 @@ cmd_file (const char *com _GL_UNUSED, const char *val, void *place)
{ {
char **pstring = (char **)place; char **pstring = (char **)place;
xfree_null (*pstring); xfree (*pstring);
/* #### If VAL is empty, perhaps should set *PLACE to NULL. */ /* #### If VAL is empty, perhaps should set *PLACE to NULL. */
@ -1418,7 +1416,7 @@ cmd_spec_progress (const char *com, const char *val, void *place_ignored _GL_UNU
exec_name, com, quote (val)); exec_name, com, quote (val));
return false; return false;
} }
xfree_null (opt.progress_type); xfree (opt.progress_type);
/* Don't call set_progress_implementation here. It will be called /* Don't call set_progress_implementation here. It will be called
in main when it becomes clear what the log output is. */ in main when it becomes clear what the log output is. */
@ -1569,7 +1567,7 @@ cmd_spec_useragent (const char *com, const char *val, void *place_ignored _GL_UN
exec_name, com, quote (val)); exec_name, com, quote (val));
return false; return false;
} }
xfree_null (opt.useragent); xfree (opt.useragent);
opt.useragent = xstrdup (val); opt.useragent = xstrdup (val);
return true; return true;
} }
@ -1769,11 +1767,11 @@ cleanup (void)
log_cleanup (); log_cleanup ();
netrc_cleanup (); netrc_cleanup ();
xfree_null (opt.choose_config); xfree (opt.choose_config);
xfree_null (opt.lfilename); xfree (opt.lfilename);
xfree_null (opt.dir_prefix); xfree (opt.dir_prefix);
xfree_null (opt.input_filename); xfree (opt.input_filename);
xfree_null (opt.output_document); xfree (opt.output_document);
free_vec (opt.accepts); free_vec (opt.accepts);
free_vec (opt.rejects); free_vec (opt.rejects);
free_vec ((char **)opt.excludes); free_vec ((char **)opt.excludes);
@ -1781,39 +1779,39 @@ cleanup (void)
free_vec (opt.domains); free_vec (opt.domains);
free_vec (opt.follow_tags); free_vec (opt.follow_tags);
free_vec (opt.ignore_tags); free_vec (opt.ignore_tags);
xfree_null (opt.progress_type); xfree (opt.progress_type);
xfree_null (opt.ftp_user); xfree (opt.ftp_user);
xfree_null (opt.ftp_passwd); xfree (opt.ftp_passwd);
xfree_null (opt.ftp_proxy); xfree (opt.ftp_proxy);
xfree_null (opt.https_proxy); xfree (opt.https_proxy);
xfree_null (opt.http_proxy); xfree (opt.http_proxy);
free_vec (opt.no_proxy); free_vec (opt.no_proxy);
xfree_null (opt.useragent); xfree (opt.useragent);
xfree_null (opt.referer); xfree (opt.referer);
xfree_null (opt.http_user); xfree (opt.http_user);
xfree_null (opt.http_passwd); xfree (opt.http_passwd);
free_vec (opt.user_headers); free_vec (opt.user_headers);
free_vec (opt.warc_user_headers); free_vec (opt.warc_user_headers);
# ifdef HAVE_SSL # ifdef HAVE_SSL
xfree_null (opt.cert_file); xfree (opt.cert_file);
xfree_null (opt.private_key); xfree (opt.private_key);
xfree_null (opt.ca_directory); xfree (opt.ca_directory);
xfree_null (opt.ca_cert); xfree (opt.ca_cert);
xfree_null (opt.crl_file); xfree (opt.crl_file);
xfree_null (opt.random_file); xfree (opt.random_file);
xfree_null (opt.egd_file); xfree (opt.egd_file);
# endif # endif
xfree_null (opt.bind_address); xfree (opt.bind_address);
xfree_null (opt.cookies_input); xfree (opt.cookies_input);
xfree_null (opt.cookies_output); xfree (opt.cookies_output);
xfree_null (opt.user); xfree (opt.user);
xfree_null (opt.passwd); xfree (opt.passwd);
xfree_null (opt.base_href); xfree (opt.base_href);
xfree_null (opt.method); xfree (opt.method);
xfree_null (opt.post_file_name); xfree (opt.post_file_name);
xfree_null (opt.post_data); xfree (opt.post_data);
xfree_null (opt.body_data); xfree (opt.body_data);
xfree_null (opt.body_file); xfree (opt.body_file);
#endif /* DEBUG_MALLOC */ #endif /* DEBUG_MALLOC */
} }

View File

@ -295,7 +295,7 @@ remote_to_utf8 (struct iri *iri, const char *str, const char **new)
/* Test if something was converted */ /* Test if something was converted */
if (*new && !strcmp (str, *new)) if (*new && !strcmp (str, *new))
{ {
xfree ((char *) *new); xfree (*new);
return false; return false;
} }
@ -329,9 +329,9 @@ struct iri *iri_dup (const struct iri *src)
void void
iri_free (struct iri *i) iri_free (struct iri *i)
{ {
xfree_null (i->uri_encoding); xfree (i->uri_encoding);
xfree_null (i->content_encoding); xfree (i->content_encoding);
xfree_null (i->orig_url); xfree (i->orig_url);
xfree (i); xfree (i);
} }

View File

@ -156,11 +156,7 @@ static void
free_log_line (int num) free_log_line (int num)
{ {
struct log_ln *ln = log_lines + num; struct log_ln *ln = log_lines + num;
if (ln->malloced_line)
{
xfree (ln->malloced_line); xfree (ln->malloced_line);
ln->malloced_line = NULL;
}
ln->content = NULL; ln->content = NULL;
} }
@ -451,7 +447,6 @@ log_vprintf_internal (struct logvprintf_state *state, const char *fmt,
FPUTS (write_ptr, fp); FPUTS (write_ptr, fp);
if (warcfp != NULL) if (warcfp != NULL)
FPUTS (write_ptr, warcfp); FPUTS (write_ptr, warcfp);
if (state->bigmsg)
xfree (state->bigmsg); xfree (state->bigmsg);
flush: flush:
@ -847,7 +842,7 @@ log_cleanup (void)
{ {
size_t i; size_t i;
for (i = 0; i < countof (ring); i++) for (i = 0; i < countof (ring); i++)
xfree_null (ring[i].buffer); xfree (ring[i].buffer);
} }
/* When SIGHUP or SIGUSR1 are received, the output is redirected /* When SIGHUP or SIGUSR1 are received, the output is redirected

View File

@ -889,7 +889,7 @@ format_and_print_line (const char *prefix, const char *line,
} }
if (printf ("%s ", token) < 0) if (printf ("%s ", token) < 0)
{ {
xfree_null (line_dup); xfree (line_dup);
return -1; return -1;
} }
remaining_chars -= strlen (token) + 1; /* account for " " */ remaining_chars -= strlen (token) + 1; /* account for " " */
@ -1481,13 +1481,11 @@ for details.\n\n"));
{ {
setoptval ("bodydata", opt.post_data, "body-data"); setoptval ("bodydata", opt.post_data, "body-data");
xfree(opt.post_data); xfree(opt.post_data);
opt.post_data = NULL;
} }
else else
{ {
setoptval ("bodyfile", opt.post_file_name, "body-file"); setoptval ("bodyfile", opt.post_file_name, "body-file");
xfree(opt.post_file_name); xfree(opt.post_file_name);
opt.post_file_name = NULL;
} }
} }
@ -1698,8 +1696,8 @@ outputting to a regular file.\n"));
if (unlink (filename)) if (unlink (filename))
logprintf (LOG_NOTQUIET, "unlink: %s\n", strerror (errno)); logprintf (LOG_NOTQUIET, "unlink: %s\n", strerror (errno));
} }
xfree_null (redirected_URL); xfree (redirected_URL);
xfree_null (filename); xfree (filename);
url_free (url_parsed); url_free (url_parsed);
} }
iri_free (iri); iri_free (iri);

View File

@ -367,8 +367,8 @@ static int old_percentage = -1;
void void
ws_changetitle (const char *url) ws_changetitle (const char *url)
{ {
xfree_null (title_buf); xfree (title_buf);
xfree_null (curr_url); xfree (curr_url);
title_buf = xmalloc (strlen (url) + 20); title_buf = xmalloc (strlen (url) + 20);
curr_url = xstrdup (url); curr_url = xstrdup (url);
old_percentage = -1; old_percentage = -1;

View File

@ -163,7 +163,7 @@ search_netrc (const char *host, const char **acc, const char **passwd,
/* Normally, these functions would be defined by your package. */ /* Normally, these functions would be defined by your package. */
# define xmalloc malloc # define xmalloc malloc
# define xfree free # define xfree(p) do { free ((void *) (p)); p = NULL; } while (0)
# define xstrdup strdup # define xstrdup strdup
# define xrealloc realloc # define xrealloc realloc
@ -183,9 +183,9 @@ maybe_add_to_list (acc_t **newentry, acc_t **list)
if (a && ! a->acc) if (a && ! a->acc)
{ {
/* Free any allocated space. */ /* Free any allocated space. */
xfree_null (a->host); xfree (a->host);
xfree_null (a->acc); xfree (a->acc);
xfree_null (a->passwd); xfree (a->passwd);
} }
else else
{ {
@ -424,9 +424,9 @@ free_netrc(acc_t *l)
while (l) while (l)
{ {
t = l->next; t = l->next;
xfree_null (l->acc); xfree (l->acc);
xfree_null (l->passwd); xfree (l->passwd);
xfree_null (l->host); xfree (l->host);
xfree (l); xfree (l);
l = t; l = t;
} }

View File

@ -416,7 +416,7 @@ openssl_errstr (int fd _GL_UNUSED, void *arg)
return NULL; return NULL;
/* Get rid of previous contents of ctx->last_error, if any. */ /* Get rid of previous contents of ctx->last_error, if any. */
xfree_null (ctx->last_error); xfree (ctx->last_error);
/* Iterate over OpenSSL's error stack and accumulate errors in the /* Iterate over OpenSSL's error stack and accumulate errors in the
last_error buffer, separated by "; ". This is better than using last_error buffer, separated by "; ". This is better than using
@ -460,7 +460,7 @@ openssl_close (int fd, void *arg)
SSL_shutdown (conn); SSL_shutdown (conn);
SSL_free (conn); SSL_free (conn);
xfree_null (ctx->last_error); xfree (ctx->last_error);
xfree (ctx); xfree (ctx);
close (fd); close (fd);

View File

@ -461,8 +461,8 @@ retrieve_tree (struct url *start_url_parsed, struct iri *pi)
} }
xfree (url); xfree (url);
xfree_null (referer); xfree (referer);
xfree_null (file); xfree (file);
iri_free (i); iri_free (i);
} }
@ -478,7 +478,7 @@ retrieve_tree (struct url *start_url_parsed, struct iri *pi)
{ {
iri_free (d6); iri_free (d6);
xfree (d1); xfree (d1);
xfree_null (d2); xfree (d2);
} }
} }
url_queue_delete (queue); url_queue_delete (queue);

View File

@ -404,7 +404,7 @@ free_specs (struct robot_specs *specs)
int i; int i;
for (i = 0; i < specs->count; i++) for (i = 0; i < specs->count; i++)
xfree (specs->paths[i].path); xfree (specs->paths[i].path);
xfree_null (specs->paths); xfree (specs->paths);
xfree (specs); xfree (specs);
} }
@ -579,7 +579,6 @@ res_retrieve_file (const char *url, char **file, struct iri *iri)
allocated the file name, deallocate is here so that the allocated the file name, deallocate is here so that the
caller doesn't have to worry about it. */ caller doesn't have to worry about it. */
xfree (*file); xfree (*file);
*file = NULL;
} }
return err == RETROK; return err == RETROK;
} }

View File

@ -550,7 +550,7 @@ fd_read_hunk (int fd, hunk_terminator_t terminator, long sizehint, long maxsize)
rdlen = fd_read (fd, hunk + tail, remain, 0); rdlen = fd_read (fd, hunk + tail, remain, 0);
if (rdlen < 0) if (rdlen < 0)
{ {
xfree_null (hunk); xfree (hunk);
return NULL; return NULL;
} }
tail += rdlen; tail += rdlen;
@ -839,7 +839,6 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
assert (mynewloc != NULL); assert (mynewloc != NULL);
if (local_file)
xfree (local_file); xfree (local_file);
/* The HTTP specs only allow absolute URLs to appear in /* The HTTP specs only allow absolute URLs to appear in
@ -854,8 +853,7 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
the content encoding. */ the content encoding. */
iri->utf8_encode = opt.enable_iri; iri->utf8_encode = opt.enable_iri;
set_content_encoding (iri, NULL); set_content_encoding (iri, NULL);
xfree_null (iri->orig_url); xfree (iri->orig_url);
iri->orig_url = NULL;
/* Now, see if this new location makes sense. */ /* Now, see if this new location makes sense. */
newloc_parsed = url_parse (mynewloc, &up_error_code, iri, true); newloc_parsed = url_parse (mynewloc, &up_error_code, iri, true);
@ -964,7 +962,7 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
if (file) if (file)
*file = local_file ? local_file : NULL; *file = local_file ? local_file : NULL;
else else
xfree_null (local_file); xfree (local_file);
if (orig_parsed != u) if (orig_parsed != u)
{ {
@ -1048,8 +1046,7 @@ retrieve_from_file (const char *file, bool html, int *count)
/* Reset UTF-8 encode status */ /* Reset UTF-8 encode status */
iri->utf8_encode = opt.enable_iri; iri->utf8_encode = opt.enable_iri;
xfree_null (iri->orig_url); xfree (iri->orig_url);
iri->orig_url = NULL;
input_file = url_file; input_file = url_file;
} }
@ -1059,7 +1056,7 @@ retrieve_from_file (const char *file, bool html, int *count)
url_list = (html ? get_urls_html (input_file, NULL, NULL, iri) url_list = (html ? get_urls_html (input_file, NULL, NULL, iri)
: get_urls_file (input_file)); : get_urls_file (input_file));
xfree_null (url_file); xfree (url_file);
for (cur_url = url_list; cur_url; cur_url = cur_url->next, ++*count) for (cur_url = url_list; cur_url; cur_url = cur_url->next, ++*count)
{ {
@ -1114,8 +1111,8 @@ Removing file due to --delete-after in retrieve_from_file():\n"));
dt &= ~RETROKF; dt &= ~RETROKF;
} }
xfree_null (new_file); xfree (new_file);
xfree_null (filename); xfree (filename);
iri_free (tmpiri); iri_free (tmpiri);
} }
@ -1191,7 +1188,7 @@ free_urlpos (struct urlpos *l)
struct urlpos *next = l->next; struct urlpos *next = l->next;
if (l->url) if (l->url)
url_free (l->url); url_free (l->url);
xfree_null (l->local_name); xfree (l->local_name);
xfree (l); xfree (l);
l = next; l = next;
} }

View File

@ -706,7 +706,7 @@ url_parse (const char *url, int *error, struct iri *iri, bool percent_encode)
new_url = NULL; new_url = NULL;
else else
{ {
xfree_null (iri->orig_url); xfree (iri->orig_url);
iri->orig_url = xstrdup (url); iri->orig_url = xstrdup (url);
url_encoded = reencode_escapes (new_url); url_encoded = reencode_escapes (new_url);
if (url_encoded != new_url) if (url_encoded != new_url)
@ -917,7 +917,7 @@ url_parse (const char *url, int *error, struct iri *iri, bool percent_encode)
u->url = url_string (u, URL_AUTH_SHOW); u->url = url_string (u, URL_AUTH_SHOW);
if (url_encoded != url) if (url_encoded != url)
xfree ((char *) url_encoded); xfree (url_encoded);
} }
else else
{ {
@ -932,7 +932,7 @@ url_parse (const char *url, int *error, struct iri *iri, bool percent_encode)
error: error:
/* Cleanup in case of error: */ /* Cleanup in case of error: */
if (url_encoded && url_encoded != url) if (url_encoded && url_encoded != url)
xfree ((char *) url_encoded); xfree (url_encoded);
/* Transmit the error code to the caller, if the caller wants to /* Transmit the error code to the caller, if the caller wants to
know. */ know. */
@ -1177,11 +1177,11 @@ url_free (struct url *url)
xfree (url->path); xfree (url->path);
xfree (url->url); xfree (url->url);
xfree_null (url->params); xfree (url->params);
xfree_null (url->query); xfree (url->query);
xfree_null (url->fragment); xfree (url->fragment);
xfree_null (url->user); xfree (url->user);
xfree_null (url->passwd); xfree (url->passwd);
xfree (url->dir); xfree (url->dir);
xfree (url->file); xfree (url->file);

View File

@ -47,12 +47,7 @@ as that of the covered work. */
#define alloca_array(type, size) ((type *) alloca ((size) * sizeof (type))) #define alloca_array(type, size) ((type *) alloca ((size) * sizeof (type)))
#define xfree free #define xfree(p) do { free ((void *) (p)); p = NULL; } while (0)
/* Free P if it is non-NULL. C requires free() to behaves this way by
default, but Wget's code is historically careful not to pass NULL
to free. This allows us to assert p!=NULL in xfree to check
additional errors. (But we currently don't do that!) */
#define xfree_null(p) if (!(p)) ; else xfree (p)
struct hash_table; struct hash_table;

View File

@ -939,9 +939,9 @@ warc_process_cdx_line (char *lineptr, int field_num_original_url,
} }
else else
{ {
xfree_null(checksum); xfree(checksum);
xfree_null(original_url); xfree(original_url);
xfree_null(record_id); xfree(record_id);
} }
} }