i965: Check calloc return value in gather_statistics_results()
authorJuha-Pekka Heikkila <juhapekka.heikkila@gmail.com>
Thu, 8 May 2014 13:19:51 +0000 (16:19 +0300)
committerVille Syrjälä <ville.syrjala@linux.intel.com>
Thu, 26 Jun 2014 12:37:14 +0000 (15:37 +0300)
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 <juhapekka.heikkila@gmail.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/mesa/drivers/dri/i965/brw_performance_monitor.c

index 3f64eae57eb1d6c148e6de4d7a76c99f315e96e3..74b6ac91cc887338d537eb5db0965b507852eac5 100644 (file)
@@ -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;