From 014471cae859a34591dd1f768712aaf14788ebd2 Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Fri, 31 Jan 2014 16:18:47 +0200 Subject: [PATCH] android/hal-audio: Do not allocate memory if fd < 0 Fixes memory leak when returning bad fd we still allocate memory which is not freed in the caller function audio_open_output_stream(). --- android/hal-audio.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/android/hal-audio.c b/android/hal-audio.c index 35bafe77e..a6347afea 100644 --- a/android/hal-audio.c +++ b/android/hal-audio.c @@ -637,6 +637,9 @@ static int audio_ipc_cmd(uint8_t service_id, uint8_t opcode, uint16_t len, break; } } + + if (*fd < 0) + goto failed; } if (rsp_len) @@ -713,7 +716,6 @@ static int ipc_open_stream_cmd(uint8_t endpoint_id, uint16_t *mtu, int *fd, result = audio_ipc_cmd(AUDIO_SERVICE_ID, AUDIO_OP_OPEN_STREAM, sizeof(cmd), &cmd, &rsp_len, rsp, fd); - if (result == AUDIO_STATUS_SUCCESS) { size_t buf_len = sizeof(struct audio_preset) + rsp->preset[0].len; -- 2.47.3