sparkfun / Arduino_Apollo3

Arduino core to support the Apollo3 microcontroller from Ambiq Micro
83 stars 38 forks source link

SPI.end incorrect check #442

Closed paulvha closed 2 years ago

paulvha commented 2 years ago

I have created a pull request for SPI.end. In the current setup, it tries to remove the dev-instance if it does NOT exist (which only happens if you have NOT called SPI.begin()).

    if (! dev) {
        delete dev;
    }

As a result the dev-instance is never removed, memory released, when the instance was set

it should read :


    if (dev) {
        delete dev;
    }

regards, Paul

Wenn0101 commented 2 years ago

Fix is in dev and scheduled for release 2.2.1

PaulZC commented 2 years ago

Hi @Wenn0101 ,

Are we sure that delete sets dev to NULL?

I'm wondering if the end code should be:

void arduino::MbedSPI::end() {
    if (dev) {
        delete dev;
        dev = NULL;
    }
}

I can't take credit for this. I've seen @paulvha add the NULL in other places.

Cheers, Paul