Commit 012aef07 authored by Markus Armbruster's avatar Markus Armbruster Committed by Michael Tokarev
Browse files

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



My Coccinelle semantic patch finds a few more, because it also fixes up
the equally pointless conditional

    if (foo) {
        free(foo);
        foo = NULL;
    }

Result (feel free to squash it into your patch):

Signed-off-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 ef1e1e07
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -234,10 +234,8 @@ static int fifo_empty_elements_number(Exynos4210UartFIFO *q)

static void fifo_reset(Exynos4210UartFIFO *q)
{
    if (q->data != NULL) {
    g_free(q->data);
    q->data = NULL;
    }

    q->data = (uint8_t *)g_malloc0(q->size);

+2 −4
Original line number Diff line number Diff line
@@ -3391,10 +3391,8 @@ static void pci_rtl8139_uninit(PCIDevice *dev)
{
    RTL8139State *s = RTL8139(dev);

    if (s->cplus_txbuffer) {
    g_free(s->cplus_txbuffer);
    s->cplus_txbuffer = NULL;
    }
    timer_del(s->timer);
    timer_free(s->timer);
    qemu_del_nic(s->nic);
+4 −8
Original line number Diff line number Diff line
@@ -1460,10 +1460,8 @@ static void spapr_pci_pre_save(void *opaque)
    gpointer key, value;
    int i;

    if (sphb->msi_devs) {
    g_free(sphb->msi_devs);
    sphb->msi_devs = NULL;
    }
    sphb->msi_devs_num = g_hash_table_size(sphb->msi);
    if (!sphb->msi_devs_num) {
        return;
@@ -1490,10 +1488,8 @@ static int spapr_pci_post_load(void *opaque, int version_id)
                         sizeof(sphb->msi_devs[i].value));
        g_hash_table_insert(sphb->msi, key, value);
    }
    if (sphb->msi_devs) {
    g_free(sphb->msi_devs);
    sphb->msi_devs = NULL;
    }
    sphb->msi_devs_num = 0;

    return 0;
+2 −4
Original line number Diff line number Diff line
@@ -1169,11 +1169,9 @@ static void sdhci_uninitfn(SDHCIState *s)
    qemu_free_irq(s->eject_cb);
    qemu_free_irq(s->ro_cb);

    if (s->fifo_buffer) {
    g_free(s->fifo_buffer);
    s->fifo_buffer = NULL;
}
}

const VMStateDescription sdhci_vmstate = {
    .name = "sdhci",
+2 −4
Original line number Diff line number Diff line
@@ -95,11 +95,9 @@ static void usb_ehci_pci_exit(PCIDevice *dev)

    usb_ehci_unrealize(s, DEVICE(dev), NULL);

    if (s->irq) {
    g_free(s->irq);
    s->irq = NULL;
}
}

static void usb_ehci_pci_reset(DeviceState *dev)
{
Loading