summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDerek Foreman <derekf@osg.samsung.com>2016-09-19 10:34:44 -0500
committerDerek Foreman <derekf@osg.samsung.com>2016-09-19 10:47:02 -0500
commit9799d45ee7ecc9667fe079ab8121ca9da008db3e (patch)
tree31a290cd497300efb8245bd6d34cb45d58c7281e /src
parentb324b754f3390e2ba7404bcc27e59d43514c5a0f (diff)
eina_cpu: Fix coverity defects in eina_cpu_map_init
Fixes a potential fd leak on failure and wrong core to speed mapping on systems with > 31 cpu cores CID: 1362860 CID: 1362859 CID: 1362857
Diffstat (limited to 'src')
-rw-r--r--src/lib/eina/eina_cpu.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/lib/eina/eina_cpu.c b/src/lib/eina/eina_cpu.c
index b5e6b90d94..9f4ab4b0be 100644
--- a/src/lib/eina/eina_cpu.c
+++ b/src/lib/eina/eina_cpu.c
@@ -323,6 +323,7 @@ eina_cpu_map_init(void)
323 fastest_core_speed = -1; 323 fastest_core_speed = -1;
324 324
325#if defined (__linux__) || defined(__GLIBC__) 325#if defined (__linux__) || defined(__GLIBC__)
326 FILE *f = NULL;
326 Eina_Iterator *it; 327 Eina_Iterator *it;
327 Eina_Strbuf *fname; 328 Eina_Strbuf *fname;
328 const Eina_File_Direct_Info *f_info; 329 const Eina_File_Direct_Info *f_info;
@@ -339,7 +340,6 @@ eina_cpu_map_init(void)
339 eina_str_has_prefix(f_info->path, 340 eina_str_has_prefix(f_info->path,
340 "/sys/devices/system/cpu/cpufreq/policy")) 341 "/sys/devices/system/cpu/cpufreq/policy"))
341 { 342 {
342 FILE *f;
343 int num, speed; 343 int num, speed;
344 344
345 eina_strbuf_append_printf(fname, "%s%s", f_info->path, "/cpuinfo_max_freq"); 345 eina_strbuf_append_printf(fname, "%s%s", f_info->path, "/cpuinfo_max_freq");
@@ -349,6 +349,7 @@ eina_cpu_map_init(void)
349 speed = -1; 349 speed = -1;
350 num = fscanf(f, "%d", &speed); 350 num = fscanf(f, "%d", &speed);
351 fclose(f); 351 fclose(f);
352 f = NULL;
352 if ((num != 1) || (speed == -1)) goto err; 353 if ((num != 1) || (speed == -1)) goto err;
353 354
354 slowest_core_speed = MIN(speed, slowest_core_speed); 355 slowest_core_speed = MIN(speed, slowest_core_speed);
@@ -370,15 +371,17 @@ eina_cpu_map_init(void)
370 { 371 {
371 corelist = malloc(sizeof(*corelist)); 372 corelist = malloc(sizeof(*corelist));
372 if (!corelist) goto err; 373 if (!corelist) goto err;
373 *corelist = 1 << core; 374 *corelist = 1LL << core;
374 eina_hash_add(cpu_hash, &speed, corelist); 375 eina_hash_add(cpu_hash, &speed, corelist);
375 } 376 }
376 *corelist |= 1 << core; 377 *corelist |= 1LL << core;
377 } while (num != EOF); 378 } while (num != EOF);
378 fclose(f); 379 fclose(f);
380 f = NULL;
379 } 381 }
380 } 382 }
381err: 383err:
384 if (f) fclose(f);
382 eina_strbuf_free(fname); 385 eina_strbuf_free(fname);
383 eina_iterator_free(it); 386 eina_iterator_free(it);
384#endif 387#endif