From 4a0b3579d4a104c22ec3dfb31ecf36ac489afc5d Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 11 Sep 2015 19:08:16 -0700 Subject: [PATCH] soundio_disconnect: allow NULL parameter --- src/soundio.cpp | 5 +++-- test/unit_tests.cpp | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/soundio.cpp b/src/soundio.cpp index 064e239..e06c2d8 100644 --- a/src/soundio.cpp +++ b/src/soundio.cpp @@ -154,8 +154,6 @@ const char *soundio_backend_name(enum SoundIoBackend backend) { void soundio_destroy(struct SoundIo *soundio) { SoundIoPrivate *si = (SoundIoPrivate *)soundio; - if (!si) - return; soundio_disconnect(soundio); @@ -238,6 +236,9 @@ int soundio_connect_backend(SoundIo *soundio, SoundIoBackend backend) { void soundio_disconnect(struct SoundIo *soundio) { SoundIoPrivate *si = (SoundIoPrivate *)soundio; + if (!si) + return; + if (si->destroy) si->destroy(si); memset(&si->backend_data, 0, sizeof(SoundIoBackendData)); diff --git a/test/unit_tests.cpp b/test/unit_tests.cpp index ed6b921..d8a72c4 100644 --- a/test/unit_tests.cpp +++ b/test/unit_tests.cpp @@ -49,6 +49,8 @@ static void test_create_outstream(void) { soundio_outstream_destroy(outstream); soundio_device_unref(device); soundio_destroy(soundio); + soundio = NULL; + soundio_destroy(soundio); }