OSDN Git Service

android/hal-audio: Do not allocate memory if fd < 0
authorAndrei Emeltchenko <andrei.emeltchenko@intel.com>
Fri, 31 Jan 2014 14:18:47 +0000 (16:18 +0200)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Sun, 2 Feb 2014 15:43:52 +0000 (07:43 -0800)
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

index 35bafe7..a6347af 100644 (file)
@@ -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;