Skip to content

Commit f3c3a09

Browse files
committed
utils: No need to NULL protect lwc_string_unref
1 parent 869241c commit f3c3a09

File tree

5 files changed

+19
-54
lines changed

5 files changed

+19
-54
lines changed

utils/corestrings.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ nserror corestrings_fini(void)
4141
{
4242
#define CORESTRING_LWC_VALUE(NAME,VALUE) \
4343
do { \
44-
if (corestring_lwc_##NAME != NULL) { \
45-
lwc_string_unref(corestring_lwc_##NAME); \
46-
corestring_lwc_##NAME = NULL; \
47-
} \
44+
lwc_string_unref(corestring_lwc_##NAME); \
45+
corestring_lwc_##NAME = NULL; \
4846
} while (0)
4947

5048
#define CORESTRING_DOM_VALUE(NAME,VALUE) \

utils/http/cache-control.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ typedef struct http_directive {
4949
static void http_destroy_directive(http_directive *self)
5050
{
5151
lwc_string_unref(self->name);
52-
if (self->value != NULL) {
53-
lwc_string_unref(self->value);
54-
}
52+
lwc_string_unref(self->value);
5553
free(self);
5654
}
5755

@@ -90,9 +88,7 @@ static nserror http__parse_directive(const char **input,
9088

9189
directive = malloc(sizeof(*directive));
9290
if (directive == NULL) {
93-
if (value != NULL) {
94-
lwc_string_unref(value);
95-
}
91+
lwc_string_unref(value);
9692
lwc_string_unref(name);
9793
return NSERROR_NOMEM;
9894
}
@@ -189,9 +185,7 @@ static bool check_duplicates(const http_directive *directives)
189185
result &= (count(directives, name) == 1);
190186

191187
lwc_string_unref(name);
192-
if (value != NULL) {
193-
lwc_string_unref(value);
194-
}
188+
lwc_string_unref(value);
195189
} while (key != NULL);
196190

197191
return result;
@@ -290,19 +284,15 @@ nserror http_parse_cache_control(const char *header_value,
290284
corestring_lwc_no_cache, &value_str);
291285
if (error == NSERROR_OK) {
292286
no_cache = true;
293-
if (value_str != NULL) {
294-
lwc_string_unref(value_str);
295-
}
287+
lwc_string_unref(value_str);
296288
}
297289

298290
/* Find no-store */
299291
error = http_directive_list_find_item(directives,
300292
corestring_lwc_no_store, &value_str);
301293
if (error == NSERROR_OK) {
302294
no_store = true;
303-
if (value_str != NULL) {
304-
lwc_string_unref(value_str);
305-
}
295+
lwc_string_unref(value_str);
306296
}
307297

308298
http_directive_list_destroy(directives);

utils/http/strict-transport-security.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ typedef struct http_directive {
4747
static void http_destroy_directive(http_directive *self)
4848
{
4949
lwc_string_unref(self->name);
50-
if (self->value != NULL) {
51-
lwc_string_unref(self->value);
52-
}
50+
lwc_string_unref(self->value);
5351
free(self);
5452
}
5553

@@ -88,9 +86,7 @@ static nserror http__parse_directive(const char **input,
8886

8987
directive = malloc(sizeof(*directive));
9088
if (directive == NULL) {
91-
if (value != NULL) {
92-
lwc_string_unref(value);
93-
}
89+
lwc_string_unref(value);
9490
lwc_string_unref(name);
9591
return NSERROR_NOMEM;
9692
}
@@ -187,9 +183,7 @@ static bool check_duplicates(const http_directive *directives)
187183
result &= (count(directives, name) == 1);
188184

189185
lwc_string_unref(name);
190-
if (value != NULL) {
191-
lwc_string_unref(value);
192-
}
186+
lwc_string_unref(value);
193187
} while (key != NULL);
194188

195189
return result;

utils/nsurl/nsurl.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,9 +641,7 @@ nserror nsurl_replace_query(const nsurl *url, const char *query,
641641
/* Create NetSurf URL object */
642642
*new_url = malloc(sizeof(nsurl) + length + 1); /* Add 1 for \0 */
643643
if (*new_url == NULL) {
644-
if (query_len > 0) {
645-
lwc_string_unref(lwc_query);
646-
}
644+
lwc_string_unref(lwc_query);
647645
return NSERROR_NOMEM;
648646
}
649647

utils/nsurl/private.h

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -137,29 +137,14 @@ void nsurl__calc_hash(nsurl *url);
137137
*/
138138
static inline void nsurl__components_destroy(struct nsurl_components *c)
139139
{
140-
if (c->scheme)
141-
lwc_string_unref(c->scheme);
142-
143-
if (c->username)
144-
lwc_string_unref(c->username);
145-
146-
if (c->password)
147-
lwc_string_unref(c->password);
148-
149-
if (c->host)
150-
lwc_string_unref(c->host);
151-
152-
if (c->port)
153-
lwc_string_unref(c->port);
154-
155-
if (c->path)
156-
lwc_string_unref(c->path);
157-
158-
if (c->query)
159-
lwc_string_unref(c->query);
160-
161-
if (c->fragment)
162-
lwc_string_unref(c->fragment);
140+
lwc_string_unref(c->scheme);
141+
lwc_string_unref(c->username);
142+
lwc_string_unref(c->password);
143+
lwc_string_unref(c->host);
144+
lwc_string_unref(c->port);
145+
lwc_string_unref(c->path);
146+
lwc_string_unref(c->query);
147+
lwc_string_unref(c->fragment);
163148
}
164149

165150
#endif

0 commit comments

Comments
 (0)