From ca198b5eb5a328091f6dc17e3f4725742f66de30 Mon Sep 17 00:00:00 2001 From: Arun Khandavalli Date: Tue, 26 Apr 2016 20:53:35 +0530 Subject: [PATCH] qcacld-3.0: Allocate memory for set_offload and program at once qcacld-2.0 to qcacld-3.0 propagation Presently, in BPF set_offload structure and the filter program are allocated separately. In certain error paths the program is not freed correctly because of which there can be memory leaks. Have a single allocation for the set_offload and program to avoid any memory leaks. Change-Id: I097d3408cc89c26e015fd6aee8668f53e8f64cf7 CRs-Fixed: 1006522 --- core/sme/src/common/sme_api.c | 17 ++++------------- core/wma/src/wma_features.c | 1 - 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/core/sme/src/common/sme_api.c b/core/sme/src/common/sme_api.c index 2983525148fc..57c167a44b1f 100644 --- a/core/sme/src/common/sme_api.c +++ b/core/sme/src/common/sme_api.c @@ -16064,7 +16064,8 @@ QDF_STATUS sme_set_bpf_instructions(tHalHandle hal, cds_msg_t cds_msg; struct sir_bpf_set_offload *set_offload; - set_offload = qdf_mem_malloc(sizeof(*set_offload)); + set_offload = qdf_mem_malloc(sizeof(*set_offload) + + req->current_length); if (NULL == set_offload) { QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR, @@ -16078,14 +16079,8 @@ QDF_STATUS sme_set_bpf_instructions(tHalHandle hal, set_offload->total_length = req->total_length; set_offload->current_length = req->current_length; if (set_offload->total_length) { - set_offload->program = qdf_mem_malloc(sizeof(uint8_t) * - req->current_length); - if (NULL == set_offload->program) { - QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR, - FL("Failed to alloc instruction memory")); - qdf_mem_free(set_offload); - return QDF_STATUS_E_NOMEM; - } + set_offload->program = ((uint8_t *)set_offload) + + sizeof(*set_offload); qdf_mem_copy(set_offload->program, req->program, set_offload->current_length); } @@ -16100,16 +16095,12 @@ QDF_STATUS sme_set_bpf_instructions(tHalHandle hal, QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR, FL("Post BPF set offload msg fail")); status = QDF_STATUS_E_FAILURE; - if (set_offload->total_length) - qdf_mem_free(set_offload->program); qdf_mem_free(set_offload); } sme_release_global_lock(&mac_ctx->sme); } else { QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR, FL("sme_acquire_global_lock failed")); - if (set_offload->total_length) - qdf_mem_free(set_offload->program); qdf_mem_free(set_offload); } return status; diff --git a/core/wma/src/wma_features.c b/core/wma/src/wma_features.c index 72f19099c716..567ed6e7abe4 100644 --- a/core/wma/src/wma_features.c +++ b/core/wma/src/wma_features.c @@ -7907,7 +7907,6 @@ QDF_STATUS wma_set_bpf_instructions(tp_wma_handle wma, buf_ptr += WMI_TLV_HDR_SIZE; qdf_mem_copy(buf_ptr, bpf_set_offload->program, bpf_set_offload->current_length); - qdf_mem_free(bpf_set_offload->program); } if (wmi_unified_cmd_send(wma->wmi_handle, wmi_buf, len,