From 375943bc0a99bec6e4d07b07acd0e9004b2a9ea0 Mon Sep 17 00:00:00 2001 From: Juha-Pekka Heikkila Date: Thu, 8 May 2014 16:19:51 +0300 Subject: [PATCH] i965: Check calloc return value in gather_statistics_results() Check calloc return value and report on error, also later skip results handling if there was no memory to store results to. Signed-off-by: Juha-Pekka Heikkila Reviewed-by: Ian Romanick --- src/mesa/drivers/dri/i965/brw_performance_monitor.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/mesa/drivers/dri/i965/brw_performance_monitor.c b/src/mesa/drivers/dri/i965/brw_performance_monitor.c index 3f64eae57eb..74b6ac91cc8 100644 --- a/src/mesa/drivers/dri/i965/brw_performance_monitor.c +++ b/src/mesa/drivers/dri/i965/brw_performance_monitor.c @@ -610,6 +610,10 @@ gather_statistics_results(struct brw_context *brw, ctx->PerfMonitor.Groups[PIPELINE_STATS_COUNTERS].NumCounters; monitor->pipeline_stats_results = calloc(num_counters, sizeof(uint64_t)); + if (monitor->pipeline_stats_results == NULL) { + _mesa_error_no_memory(__func__); + return; + } drm_intel_bo_map(monitor->pipeline_stats_bo, false); uint64_t *start = monitor->pipeline_stats_bo->virtual; @@ -1318,9 +1322,18 @@ brw_get_perf_monitor_result(struct gl_context *ctx, const int num_counters = ctx->PerfMonitor.Groups[PIPELINE_STATS_COUNTERS].NumCounters; - if (!monitor->pipeline_stats_results) + if (!monitor->pipeline_stats_results) { gather_statistics_results(brw, monitor); + /* Check if we did really get the results */ + if (!monitor->pipeline_stats_results) { + if (bytes_written) { + *bytes_written = 0; + } + return; + } + } + for (int i = 0; i < num_counters; i++) { if (BITSET_TEST(m->ActiveCounters[PIPELINE_STATS_COUNTERS], i)) { data[offset++] = PIPELINE_STATS_COUNTERS; -- 2.11.0