Permalink
Browse files

potential fix for #2606

  • Loading branch information...
1 parent e806ad3 commit 58785572eb1225af4a62fab057fa425df7d8f60d @bnoordhuis committed Jan 24, 2012
Showing with 14 additions and 3 deletions.
  1. +14 −3 deps/uv/src/unix/freebsd.c
@@ -197,10 +197,12 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
unsigned int ticks = (unsigned int)sysconf(_SC_CLK_TCK),
multiplier = ((uint64_t)1000L / ticks), cpuspeed, maxcpus,
cur = 0;
+ uv_cpu_info_t* cpu_info;
char model[512];
+ long* cp_times;
int numcpus;
size_t size;
- uv_cpu_info_t* cpu_info;
+ int i;
size = sizeof(model);
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) {
free(*cpu_infos);
return uv__new_sys_error(errno);
}
+
size = maxcpus * CPUSTATES * sizeof(long);
- long cp_times[size];
+
+ cp_times = malloc(size);
+ if (cp_times == NULL) {
+ free(*cpu_infos);
+ return uv__new_sys_error(ENOMEM);
+ }
+
if (sysctlbyname("kern.cp_times", &cp_times, &size, NULL, 0) < 0) {
+ free(cpu_times);
free(*cpu_infos);
return uv__new_sys_error(errno);
}
- for (int i = 0; i < numcpus; i++) {
+ for (i = 0; i < numcpus; i++) {
cpu_info = &(*cpu_infos)[i];
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) {
cur+=CPUSTATES;
}
+ free(cpu_times);
return uv_ok_;
}

0 comments on commit 5878557

Please sign in to comment.