Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a5453442 authored by Kevin Rocard's avatar Kevin Rocard
Browse files

HAL sndmonitor: Improve cleanup on error and deinit



Some resources were still leaked during sndmonitor deinit. That made
tests failed when the hal process had reach its 256 max fd open during
tests.
All file descriptor open during init should now be close during deinit.

Some memory is still leaked but as deinit of the hal is only used for
testing, it is not very important.

Test: vts-tradefed run vts --module VtsHalAudioV2_0Target
Test: call/play music/record/video...
Bug: 36311550
Change-Id: Id681a3d2dfac1692db168691ea33ef2b7d14ab2c
Signed-off-by: default avatarKevin Rocard <krocard@google.com>
parent b500b90b
Loading
Loading
Loading
Loading
+19 −9
Original line number Diff line number Diff line
@@ -582,8 +582,12 @@ int audio_extn_snd_mon_deinit()

    write(sndmonitor.intpipe[1], "Q", 1);
    pthread_join(sndmonitor.monitor_thread, (void **) NULL);
    free_sndcards();
    free_dev_events();
    listeners_deinit();
    free_sndcards();
    close(sndmonitor.intpipe[0]);
    close(sndmonitor.intpipe[1]);

    sndmonitor.initcheck = 0;
    return 0;
}
@@ -597,13 +601,13 @@ int audio_extn_snd_mon_init()
    sndmonitor.initcheck = false;

    if (pipe(sndmonitor.intpipe) < 0)
        return -ENODEV;
        goto pipe_error;

    if (enum_sndcards() < 0)
        return -ENODEV;
        goto enum_sncards_error;

    if (listeners_init() < 0)
        return -ENODEV;
        goto listeners_error;

#ifdef MONITOR_DEVICE_EVENTS
    enum_dev_events(); // failure here isn't fatal
@@ -614,15 +618,21 @@ int audio_extn_snd_mon_init()
                             monitor_thread_loop, NULL);

    if (ret) {
        goto monitor_thread_create_error;
    }
    sndmonitor.initcheck = true;
    return 0;

monitor_thread_create_error:
    listeners_deinit();
listeners_error:
    free_sndcards();
        free_dev_events();
enum_sncards_error:
    close(sndmonitor.intpipe[0]);
    close(sndmonitor.intpipe[1]);
pipe_error:
    return -ENODEV;
}
    sndmonitor.initcheck = true;
    return 0;
}

int audio_extn_snd_mon_register_listener(void *stream, snd_mon_cb cb)
{
+2 −1
Original line number Diff line number Diff line
@@ -4054,10 +4054,11 @@ static int adev_close(hw_device_t *device)
    if (!adev)
        return 0;

    audio_extn_snd_mon_unregister_listener(adev);
    audio_extn_snd_mon_deinit();

    audio_extn_tfa_98xx_deinit();

    audio_extn_snd_mon_unregister_listener(adev);
    pthread_mutex_lock(&adev_init_lock);

    if ((--audio_device_ref_count) == 0) {