Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

potential fix for #2606

  • Loading branch information...
commit 58785572eb1225af4a62fab057fa425df7d8f60d 1 parent e806ad3
Ben Noordhuis authored January 24, 2012

Showing 1 changed file with 14 additions and 3 deletions. Show diff stats Hide diff stats

  1. 17  deps/uv/src/unix/freebsd.c
17  deps/uv/src/unix/freebsd.c
@@ -197,10 +197,12 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
197 197
   unsigned int ticks = (unsigned int)sysconf(_SC_CLK_TCK),
198 198
                multiplier = ((uint64_t)1000L / ticks), cpuspeed, maxcpus,
199 199
                cur = 0;
  200
+  uv_cpu_info_t* cpu_info;
200 201
   char model[512];
  202
+  long* cp_times;
201 203
   int numcpus;
202 204
   size_t size;
203  
-  uv_cpu_info_t* cpu_info;
  205
+  int i;
204 206
 
205 207
   size = sizeof(model);
206 208
   if (sysctlbyname("hw.model", &model, &size, NULL, 0) < 0) {
@@ -229,14 +231,22 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
229 231
     free(*cpu_infos);
230 232
     return uv__new_sys_error(errno);
231 233
   }
  234
+
232 235
   size = maxcpus * CPUSTATES * sizeof(long);
233  
-  long cp_times[size];
  236
+
  237
+  cp_times = malloc(size);
  238
+  if (cp_times == NULL) {
  239
+    free(*cpu_infos);
  240
+    return uv__new_sys_error(ENOMEM);
  241
+  }
  242
+
234 243
   if (sysctlbyname("kern.cp_times", &cp_times, &size, NULL, 0) < 0) {
  244
+    free(cpu_times);
235 245
     free(*cpu_infos);
236 246
     return uv__new_sys_error(errno);
237 247
   }
238 248
 
239  
-  for (int i = 0; i < numcpus; i++) {
  249
+  for (i = 0; i < numcpus; i++) {
240 250
     cpu_info = &(*cpu_infos)[i];
241 251
     
242 252
     cpu_info->cpu_times.user = (uint64_t)(cp_times[CP_USER+cur]) * multiplier;
@@ -251,6 +261,7 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
251 261
     cur+=CPUSTATES;
252 262
   }
253 263
 
  264
+  free(cpu_times);
254 265
   return uv_ok_;
255 266
 }
256 267
 

0 notes on commit 5878557

Please sign in to comment.
Something went wrong with that request. Please try again.