Commit dccf55bc authored by Jan Včelák's avatar Jan Včelák 🚀

globally remove pointless null test before free()

Coccinelle patch used to perform this cleanup is included.

Change-Id: Ia367764245c845839fd22034b2b5f58b93bd54e8
parent 7f6c0eb8
//
// No null check required before calling free()
//
@@
expression E;
@@
(
-if (E) { free(E); }
+free(E);
|
-if (E != NULL) { free(E); }
+free(E);
)
......@@ -922,9 +922,7 @@ void conf_free_log(conf_log_t *log)
return;
}
if (log->file) {
free(log->file);
}
free(log->file);
/* Free loglevel mapping. */
node *n = 0, *nxt = 0;
......
......@@ -1113,13 +1113,9 @@ void knot_dname_free(knot_dname_t **dname)
return;
}
if ((*dname)->name != NULL) {
free((*dname)->name);
}
free((*dname)->name);
if((*dname)->labels != NULL) {
free((*dname)->labels);
}
free((*dname)->labels);
// slab_free(*dname);
......
......@@ -423,9 +423,7 @@ void knot_edns_free_options(knot_opt_rr_t *opt_rr)
/* Free the option data, if any. */
for (int i = 0; i < opt_rr->option_count; i++) {
knot_opt_option_t *option = &(opt_rr->options[i]);
if (option->data != NULL) {
free(option->data);
}
free(option->data);
}
free(opt_rr->options);
}
......
......@@ -448,9 +448,7 @@ dbg_ns_exec_verb(
++i;
}
if (rrsets != NULL) {
free(rrsets);
}
free(rrsets);
break;
}
case KNOT_RRTYPE_RRSIG: {
......@@ -2645,9 +2643,7 @@ rrsigs:
++i;
}
if (rrsets != NULL) {
free(rrsets);
}
free(rrsets);
/*! \todo maybe distinguish some error codes. */
//params->ret = (ret == 0) ? KNOT_EOK : KNOT_ERROR;
......
......@@ -257,7 +257,5 @@ int knot_nsec3_sha1(const knot_nsec3_params_t *params,
void knot_nsec3_params_free(knot_nsec3_params_t *params)
{
if (params->salt != NULL) {
free(params->salt);
}
free(params->salt);
}
......@@ -200,8 +200,7 @@ static int key_param_string(const void *save_to, char *value)
{
char **parameter = (char **)save_to;
if (*parameter)
free(*parameter);
free(*parameter);
*parameter = strdup(value);
return *parameter ? KNOT_EOK : KNOT_ENOMEM;
......@@ -353,8 +352,7 @@ int knot_load_key_params(const char *filename, knot_key_params_t *key_params)
if (result != KNOT_EOK)
break;
}
if (buffer)
free(buffer);
free(buffer);
fclose(fp);
free(public_key);
......@@ -424,12 +422,6 @@ int knot_copy_key_params(const knot_key_params_t *src, knot_key_params_t *dst)
return KNOT_EOK;
}
static void free_string_if_set(char *string)
{
if (string)
free(string);
}
/*!
* \brief Frees the key parameters.
*/
......@@ -440,25 +432,25 @@ int knot_free_key_params(knot_key_params_t *key_params)
if (key_params->name)
knot_dname_release(key_params->name);
free_string_if_set(key_params->secret);
free_string_if_set(key_params->modulus);
free_string_if_set(key_params->public_exponent);
free_string_if_set(key_params->private_exponent);
free_string_if_set(key_params->prime_one);
free_string_if_set(key_params->prime_two);
free_string_if_set(key_params->exponent_one);
free_string_if_set(key_params->exponent_two);
free_string_if_set(key_params->coefficient);
free_string_if_set(key_params->prime);
free_string_if_set(key_params->generator);
free_string_if_set(key_params->subprime);
free_string_if_set(key_params->base);
free_string_if_set(key_params->private_value);
free_string_if_set(key_params->public_value);
free_string_if_set(key_params->private_key);
free(key_params->secret);
free(key_params->modulus);
free(key_params->public_exponent);
free(key_params->private_exponent);
free(key_params->prime_one);
free(key_params->prime_two);
free(key_params->exponent_one);
free(key_params->exponent_two);
free(key_params->coefficient);
free(key_params->prime);
free(key_params->generator);
free(key_params->subprime);
free(key_params->base);
free(key_params->private_value);
free(key_params->public_value);
free(key_params->private_key);
memset(key_params, '\0', sizeof(knot_key_params_t));
......
......@@ -643,9 +643,7 @@ dbg_zone_exec_verb(
char *n = knot_dname_to_str(name);
dbg_zone("Error while encoding hashed name %s to base32.\n", n);
free(n);
if (name_b32 != NULL) {
free(name_b32);
}
free(name_b32);
return KNOT_ECRYPTO;
}
......
......@@ -571,9 +571,7 @@ void free_sign_context(sign_context_t *ctx)
knot_dnssec_key_free(&ctx->dnssec_key);
}
if (ctx->digest) {
free(ctx->digest);
}
free(ctx->digest);
memset(ctx, '\0', sizeof(sign_context_t));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment