PAL: free custompayload and payload to avoid memeory leak
The payload is not freed up in connectSessionDevice,
that will bring the risk of memeory leak.
Fix it by adding stream MFC configuration in configureMFC and
free payload pointer in configureMFC, and then free custom
payload in connectSessionDevice.
Change-Id: I61bf4f471ae49bb589706f2cae2f09e8f05df937
diff --git a/session/src/Session.cpp b/session/src/Session.cpp
index 7235640..848e6d2 100644
--- a/session/src/Session.cpp
+++ b/session/src/Session.cpp
@@ -829,7 +829,7 @@
return status;
}
-/* This is to set devicePP MFC(if exists) and PSPD MFC */
+/* This is to set devicePP MFC(if exists) and PSPD MFC and stream MFC*/
int Session::configureMFC(const std::shared_ptr<ResourceManager>& rm, struct pal_stream_attributes &sAttr,
struct pal_device &dAttr, const std::vector<int> &pcmDevIds, const char* intf)
{
@@ -896,6 +896,32 @@
setSlotMask(rm, sAttr, dAttr, pcmDevIds);
}
+ /* Prepare stream MFC payload */
+ if (sAttr.direction == PAL_AUDIO_INPUT) {
+ status = SessionAlsaUtils::getModuleInstanceId(mixer, pcmDevIds.at(0), intf,
+ TAG_STREAM_MFC_SR, &miid);
+ if (status == 0) {
+ PAL_DBG(LOG_TAG, "miid : %x id = %d, data %s, dev id = %d\n", miid,
+ pcmDevIds.at(0), intf, dAttr.id);
+ if (isPalPCMFormat(sAttr.in_media_config.aud_fmt_id))
+ mfcData.bitWidth = ResourceManager::palFormatToBitwidthLookup(
+ sAttr.in_media_config.aud_fmt_id);
+ else
+ mfcData.bitWidth = sAttr.in_media_config.bit_width;
+ mfcData.sampleRate = sAttr.in_media_config.sample_rate;
+ mfcData.numChannel = sAttr.in_media_config.ch_info.channels;
+ mfcData.ch_info = nullptr;
+ builder->payloadMFCConfig((uint8_t **)&payload, &payloadSize, miid, &mfcData);
+ if (payloadSize && payload) {
+ status = updateCustomPayload(payload, payloadSize);
+ freeCustomPayload(&payload, &payloadSize);
+ if (0 != status) {
+ PAL_ERR(LOG_TAG, "updateCustomPayload failed\n");
+ goto exit;
+ }
+ }
+ }
+ }
/* Prepare PSPD MFC payload */
/* Get PSPD MFC MIID and configure to match to device config */
/* This has to be done after sending all mixer controls and before connect */
diff --git a/session/src/SessionAlsaUtils.cpp b/session/src/SessionAlsaUtils.cpp
index f1e1ab8..024117c 100644
--- a/session/src/SessionAlsaUtils.cpp
+++ b/session/src/SessionAlsaUtils.cpp
@@ -2326,6 +2326,28 @@
status = -EINVAL;
goto exit;
}
+ } else if (sAttr.direction == PAL_AUDIO_INPUT &&
+ streamType == PAL_STREAM_ULTRA_LOW_LATENCY) {
+ if (sess) {
+ sess->configureMFC(rmHandle, sAttr, dAttr, pcmDevIds,
+ aifBackEndsToConnect[0].second.data());
+ sess->getCustomPayload(&payload, &payloadSize);
+ if (payload) {
+ status = SessionAlsaUtils::setMixerParameter(mixerHandle, pcmDevIds.at(0),
+ payload, payloadSize);
+ }
+ sess->freeCustomPayload();
+ payload = NULL;
+ payloadSize = 0;
+ if (status != 0) {
+ PAL_ERR(LOG_TAG, "setMixerParameter failed");
+ goto exit;
+ }
+ } else {
+ PAL_ERR(LOG_TAG, "invalid session audio object");
+ status = -EINVAL;
+ goto exit;
+ }
}
} else if (!(SessionAlsaUtils::isMmapUsecase(sAttr))) {
if (sess) {
@@ -2346,35 +2368,6 @@
goto exit;
}
}
- if (sAttr.direction == PAL_AUDIO_INPUT && streamType == PAL_STREAM_ULTRA_LOW_LATENCY) {
- status = SessionAlsaUtils::getModuleInstanceId(mixerHandle, pcmDevIds.at(0),
- aifBackEndsToConnect[0].second.data(),
- TAG_STREAM_MFC_SR, &miid);
- if (status != 0) {
- PAL_ERR(LOG_TAG, "getModuleInstanceId failed\n");
- goto exit;
- }
- PAL_DBG(LOG_TAG, "ULL record, miid : %x id = %d\n", miid, pcmDevIds.at(0));
- if (isPalPCMFormat(sAttr.in_media_config.aud_fmt_id))
- streamData.bitWidth = ResourceManager::palFormatToBitwidthLookup(
- sAttr.in_media_config.aud_fmt_id);
- else
- streamData.bitWidth = sAttr.in_media_config.bit_width;
- streamData.sampleRate = sAttr.in_media_config.sample_rate;
- streamData.numChannel = sAttr.in_media_config.ch_info.channels;
- streamData.ch_info = nullptr;
- builder->payloadMFCConfig(&payload, &payloadSize, miid, &streamData);
- if (payloadSize && payload) {
- sess->getCustomPayload(&payload, &payloadSize);
- }
- status = SessionAlsaUtils::setMixerParameter(mixerHandle, pcmDevIds.at(0),
- payload, payloadSize);
- sess->freeCustomPayload();
- if (status != 0) {
- PAL_ERR(LOG_TAG, "setMixerParameter failed");
- goto exit;
- }
- }
connectCtrl = mixer_get_ctl_by_name(mixerHandle, connectCtrlName.str().data());
if (!connectCtrl) {