Commit ef1e1e07 authored by Daniel P. Berrangé's avatar Daniel P. Berrangé Committed by Michael Tokarev
Browse files

maint: avoid useless "if (foo) free(foo)" pattern



The free() and g_free() functions both happily accept
NULL on any platform QEMU builds on. As such putting a
conditional 'if (foo)' check before calls to 'free(foo)'
merely serves to bloat the lines of code.

Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
Reviewed-by: default avatarMarkus Armbruster <armbru@redhat.com>
Reviewed-by: default avatarEric Blake <eblake@redhat.com>
Signed-off-by: default avatarMichael Tokarev <mjt@tls.msk.ru>
parent 4595a48a
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -83,9 +83,7 @@ static void set_mem_path(Object *o, const char *str, Error **errp)
        error_setg(errp, "cannot change property value");
        return;
    }
    if (fb->mem_path) {
    g_free(fb->mem_path);
    }
    fb->mem_path = g_strdup(str);
}

+1 −3
Original line number Diff line number Diff line
@@ -1355,9 +1355,7 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
            }
        }
        if (!bprm->p) {
            if (elf_interpreter) {
            free(elf_interpreter);
            }
            free (elf_phdata);
            close(bprm->fd);
            return -E2BIG;
+1 −2
Original line number Diff line number Diff line
@@ -2622,7 +2622,6 @@ build_hash_table (const sparc_opcode **opcode_table,

  memset (hash_table, 0, HASH_SIZE * sizeof (hash_table[0]));
  memset (hash_count, 0, HASH_SIZE * sizeof (hash_count[0]));
  if (hash_buf != NULL)
  free(hash_buf);
  hash_buf = malloc (sizeof (* hash_buf) * num_opcodes);
  for (i = num_opcodes - 1; i >= 0; --i)
+3 −6
Original line number Diff line number Diff line
@@ -1151,7 +1151,6 @@ static void bt_hci_reset(struct bt_hci_s *hci)
    hci->event_mask[7] = 0x00;
    hci->device.inquiry_scan = 0;
    hci->device.page_scan = 0;
    if (hci->device.lmp_name)
    g_free((void *) hci->device.lmp_name);
    hci->device.lmp_name = NULL;
    hci->device.class[0] = 0x00;
@@ -1829,7 +1828,6 @@ static void bt_submit_hci(struct HCIInfo *info,
    case cmd_opcode_pack(OGF_HOST_CTL, OCF_CHANGE_LOCAL_NAME):
        LENGTH_CHECK(change_local_name);

        if (hci->device.lmp_name)
        g_free((void *) hci->device.lmp_name);
        hci->device.lmp_name = g_strndup(PARAM(change_local_name, name),
                        sizeof(PARAM(change_local_name, name)));
@@ -2231,7 +2229,6 @@ static void bt_hci_done(struct HCIInfo *info)

    bt_device_done(&hci->device);

    if (hci->device.lmp_name)
    g_free((void *) hci->device.lmp_name);

    /* Be gentle and send DISCONNECT to all connected peers and those
+1 −2
Original line number Diff line number Diff line
@@ -594,7 +594,6 @@ static int load_uboot_image(const char *filename, hwaddr *ep, hwaddr *loadaddr,
    ret = hdr->ih_size;

out:
    if (data)
    g_free(data);
    close(fd);
    return ret;
Loading