Ver código fonte

qcacld-3.0: Fix possible memory leak of tx_time_per_power_level

It is possible tx_time_per_power_level is not freed
in last event, and it is reused in
__wma_unified_radio_tx_power_level_stats_event_handler,
the buffer size may be different for each event by
manually test.

Fix is to check if memory is freed before malloc, if
not null, free it before malloc.

Change-Id: I51064734cf97b9ff0ecbbaf27f38d5a223c91d3b
CRs-Fixed: 3057436
Jingxiang Ge 3 anos atrás
pai
commit
720bb5c8dd
1 arquivos alterados com 15 adições e 10 exclusões
  1. 15 10
      core/wma/src/wma_utils.c

+ 15 - 10
core/wma/src/wma_utils.c

@@ -1962,18 +1962,23 @@ static int __wma_unified_radio_tx_power_level_stats_event_handler(
 		return -EINVAL;
 	}
 
+	if (rs_results->tx_time_per_power_level) {
+		qdf_mem_free(rs_results->tx_time_per_power_level);
+		rs_results->tx_time_per_power_level = NULL;
+	}
+
+	rs_results->tx_time_per_power_level =
+		qdf_mem_malloc(sizeof(uint32_t) *
+			       rs_results->total_num_tx_power_levels);
 	if (!rs_results->tx_time_per_power_level) {
-		rs_results->tx_time_per_power_level = qdf_mem_malloc(
-				sizeof(uint32_t) *
-				rs_results->total_num_tx_power_levels);
-		if (!rs_results->tx_time_per_power_level) {
-			/* In error case, atleast send the radio stats without
-			 * tx_power_level stats */
-			rs_results->total_num_tx_power_levels = 0;
-			link_stats_results->nr_received++;
-			goto post_stats;
-		}
+		/* In error case, atleast send the radio stats without
+		 * tx_power_level stats
+		 */
+		rs_results->total_num_tx_power_levels = 0;
+		link_stats_results->nr_received++;
+		goto post_stats;
 	}
+
 	qdf_mem_copy(&rs_results->tx_time_per_power_level[
 					fixed_param->power_level_offset],
 		tx_power_level_values,