From e4583ab3642f33a069bd05f1c9917671fe4c28ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20R=C3=BChsen?= Date: Mon, 1 Dec 2014 17:02:33 +0100 Subject: [PATCH] Fix issues reported by static code analysis tool 'parfait' Closes: #41235 Reported-by: Jiri Kukacka --- src/ChangeLog | 8 ++++++++ src/connect.c | 2 +- src/iri.c | 11 +++++++---- src/url.c | 29 ++++++++++++++++------------- src/warc.c | 5 ++++- 5 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 920d822c..97a895e8 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2014-12-01 Tim Ruehsen + + * connect.c, iri.c, url.c, warc.c: Fix issues reported + by static code analysis tool 'parfait'. + + Closes: #41235 + Reported-by: Jiri Kukacka + 2014-11-29 Tim Ruehsen * utils.h: xfree() sets argument to NULL after freeing, diff --git a/src/connect.c b/src/connect.c index 727d6a67..661a6ba0 100644 --- a/src/connect.c +++ b/src/connect.c @@ -844,7 +844,7 @@ void * fd_transport_context (int fd) { struct transport_info *info = hash_table_get (transport_map, (void *)(intptr_t) fd); - return info->ctx; + return info ? info->ctx : NULL; } /* When fd_read/fd_write are called multiple times in a loop, they should diff --git a/src/iri.c b/src/iri.c index 849b101d..0686f301 100644 --- a/src/iri.c +++ b/src/iri.c @@ -329,10 +329,13 @@ struct iri *iri_dup (const struct iri *src) void iri_free (struct iri *i) { - xfree (i->uri_encoding); - xfree (i->content_encoding); - xfree (i->orig_url); - xfree (i); + if (i) + { + xfree (i->uri_encoding); + xfree (i->content_encoding); + xfree (i->orig_url); + xfree (i); + } } /* Set uri_encoding of struct iri i. If a remote encoding was specified, use diff --git a/src/url.c b/src/url.c index bc91d4e2..466ee77d 100644 --- a/src/url.c +++ b/src/url.c @@ -575,8 +575,8 @@ rewrite_shorthand_url (const char *url) goto http; /* Turn "foo.bar.com:path" to "ftp://foo.bar.com/path". */ - ret = aprintf ("ftp://%s", url); - ret[6 + (p - url)] = '/'; + if ((ret = aprintf ("ftp://%s", url)) != NULL) + ret[6 + (p - url)] = '/'; } else { @@ -1173,20 +1173,23 @@ url_set_file (struct url *url, const char *newfile) void url_free (struct url *url) { - xfree (url->host); - xfree (url->path); - xfree (url->url); + if (url) + { + xfree (url->host); + xfree (url->path); + xfree (url->url); - xfree (url->params); - xfree (url->query); - xfree (url->fragment); - xfree (url->user); - xfree (url->passwd); + xfree (url->params); + xfree (url->query); + xfree (url->fragment); + xfree (url->user); + xfree (url->passwd); - xfree (url->dir); - xfree (url->file); + xfree (url->dir); + xfree (url->file); - xfree (url); + xfree (url); + } } /* Create all the necessary directories for PATH (a file). Calls diff --git a/src/warc.c b/src/warc.c index e2ad09b5..5bdda1b5 100644 --- a/src/warc.c +++ b/src/warc.c @@ -1201,7 +1201,10 @@ warc_tempfile (void) #if !O_TEMPORARY if (unlink (filename) < 0) - return NULL; + { + close(fd); + return NULL; + } #endif return fdopen (fd, "wb+");