Hi,

I decided to run libpfm from the git repository through the Coverity static 
code check. I was already running Coverity on PAPI for its upcoming release, 
and figured it would be easy to do for libpfm also.  Attached are the Coverity 
results for libpfm in the git repository.

There doesn't appear to be any problems in the library code itself; most of the 
errors are in the examples and perf_examples. There are a few resource leaks, 
uninitizaled values, and unused values in the SWIG generated 
python/src/perfmon_int_wrap.c code.

-Will
Error: CHECKED_RETURN:
/builddir/build/BUILD/libpfm-4.2.0/examples/check_events.c:44: example_assign: 
Assigning: "ret" = return value from "pfm_get_pmu_info(p, &pinfo)".
/builddir/build/BUILD/libpfm-4.2.0/examples/check_events.c:45: example_checked: 
"ret" has its value checked in "ret == 0".
/builddir/build/BUILD/libpfm-4.2.0/examples/check_events.c:73: example_assign: 
Assigning: "ret" = return value from "pfm_get_pmu_info(i, &pinfo)".
/builddir/build/BUILD/libpfm-4.2.0/examples/check_events.c:74: example_checked: 
"ret" has its value checked in "ret != 0".
/builddir/build/BUILD/libpfm-4.2.0/examples/check_events.c:82: example_assign: 
Assigning: "ret" = return value from "pfm_get_pmu_info(i, &pinfo)".
/builddir/build/BUILD/libpfm-4.2.0/examples/check_events.c:83: example_checked: 
"ret" has its value checked in "ret != 0".
/builddir/build/BUILD/libpfm-4.2.0/examples/check_events.c:142: example_assign: 
Assigning: "ret" = return value from "pfm_get_pmu_info(info.pmu, &pinfo)".
/builddir/build/BUILD/libpfm-4.2.0/examples/check_events.c:143: 
example_checked: "ret" has its value checked in "ret != 0".
/builddir/build/BUILD/libpfm-4.2.0/examples/showevtinfo.c:385: example_assign: 
Assigning: "ret" = return value from "pfm_get_pmu_info(info->pmu, &pinfo)".
/builddir/build/BUILD/libpfm-4.2.0/examples/showevtinfo.c:386: example_checked: 
"ret" has its value checked in "ret".
/builddir/build/BUILD/libpfm-4.2.0/examples/showevtinfo.c:272: check_return: 
Calling function "pfm_get_pmu_info" without checking return value (as is done 
elsewhere 11 out of 13 times).
/builddir/build/BUILD/libpfm-4.2.0/examples/showevtinfo.c:272: unchecked_value: 
No check of the return value of "pfm_get_pmu_info(info->pmu, &pinfo)".

Error: CHECKED_RETURN:
/builddir/build/BUILD/libpfm-4.2.0/examples/check_events.c:44: example_assign: 
Assigning: "ret" = return value from "pfm_get_pmu_info(p, &pinfo)".
/builddir/build/BUILD/libpfm-4.2.0/examples/check_events.c:45: example_checked: 
"ret" has its value checked in "ret == 0".
/builddir/build/BUILD/libpfm-4.2.0/examples/check_events.c:73: example_assign: 
Assigning: "ret" = return value from "pfm_get_pmu_info(i, &pinfo)".
/builddir/build/BUILD/libpfm-4.2.0/examples/check_events.c:74: example_checked: 
"ret" has its value checked in "ret != 0".
/builddir/build/BUILD/libpfm-4.2.0/examples/check_events.c:82: example_assign: 
Assigning: "ret" = return value from "pfm_get_pmu_info(i, &pinfo)".
/builddir/build/BUILD/libpfm-4.2.0/examples/check_events.c:83: example_checked: 
"ret" has its value checked in "ret != 0".
/builddir/build/BUILD/libpfm-4.2.0/examples/check_events.c:142: example_assign: 
Assigning: "ret" = return value from "pfm_get_pmu_info(info.pmu, &pinfo)".
/builddir/build/BUILD/libpfm-4.2.0/examples/check_events.c:143: 
example_checked: "ret" has its value checked in "ret != 0".
/builddir/build/BUILD/libpfm-4.2.0/examples/showevtinfo.c:385: example_assign: 
Assigning: "ret" = return value from "pfm_get_pmu_info(info->pmu, &pinfo)".
/builddir/build/BUILD/libpfm-4.2.0/examples/showevtinfo.c:386: example_checked: 
"ret" has its value checked in "ret".
/builddir/build/BUILD/libpfm-4.2.0/examples/showevtinfo.c:176: check_return: 
Calling function "pfm_get_pmu_info" without checking return value (as is done 
elsewhere 11 out of 13 times).
/builddir/build/BUILD/libpfm-4.2.0/examples/showevtinfo.c:176: unchecked_value: 
No check of the return value of "pfm_get_pmu_info(info->pmu, &pinfo)".

Error: DEADCODE:
/builddir/build/BUILD/libpfm-4.2.0/python/src/perfmon_int_wrap.c:2393: 
dead_error_condition: On this path, the condition "ty" cannot be false.
/builddir/build/BUILD/libpfm-4.2.0/python/src/perfmon_int_wrap.c:2390: 
cannot_single: After this line (or expression), the value of "ty" cannot be 0.
/builddir/build/BUILD/libpfm-4.2.0/python/src/perfmon_int_wrap.c:2403: 
dead_error_line: Execution cannot reach this statement "*ptr = vptr;".

Error: FORWARD_NULL:
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/perf_util.c:321: 
var_compare_op: Comparing "ehdr" to null implies that "ehdr" might be null.
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/perf_util.c:324: var_deref_op: 
Dereferencing null variable "ehdr".

Error: FORWARD_NULL:
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/perf_util.c:321: 
var_compare_op: Comparing "fds" to null implies that "fds" might be null.
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/perf_util.c:326: 
alias_transfer: Assigning null: "hw" = "fds + idx".
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/perf_util.c:328: var_deref_op: 
Dereferencing null variable "hw".

Error: FORWARD_NULL:
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/perf_util.c:321: 
var_compare_op: Comparing "fp" to null implies that "fp" might be null.
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/perf_util.c:353: 
var_deref_model: Passing null variable "fp" to function "fprintf", which 
dereferences it.
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/perf_util.c:609: 
var_deref_model: Passing null variable "fp" to function "fputc", which 
dereferences it.

Error: MISSING_BREAK:
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/self_pipe.c:144: 
unterminated_case: This case (value -1) is not terminated by a 'break' 
statement.
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/self_pipe.c:146: fallthrough: 
The above case falls through to this one.

Error: MISSING_BREAK:
/builddir/build/BUILD/libpfm-4.2.0/examples/showevtinfo.c:771: 
unterminated_case: This case (value 120) is not terminated by a 'break' 
statement.
/builddir/build/BUILD/libpfm-4.2.0/examples/showevtinfo.c:773: fallthrough: The 
above case falls through to this one.

Error: NEGATIVE_RETURNS:
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/syst_count.c:194: 
var_tested_neg: Assigning: "(fds + i).fd" = a negative value.
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/syst_count.c:193: 
negative_returns: "(fds + i).fd" is passed to a parameter that cannot be 
negative.

Error: NEGATIVE_RETURNS:
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/syst_smpl.c:133: 
var_tested_neg: Assigning: "(fds + 0).fd" = a negative value.
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/syst_smpl.c:216: 
negative_returns: "(fds + 0).fd" is passed to a parameter that cannot be 
negative.

Error: NEGATIVE_RETURNS:
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/task_smpl.c:196: 
var_tested_neg: Assigning: "(fds + 0).fd" = a negative value.
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/task_smpl.c:279: 
negative_returns: "(fds + 0).fd" is passed to a parameter that cannot be 
negative.

Error: NEGATIVE_RETURNS:
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/syst.c:87: negative_return_fn: 
Function "sysconf(84)" returns a negative number.
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/syst.c:87: var_assign: 
Assigning: signed variable "cmax" = "sysconf".
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/syst.c:88: var_assign: 
Assigning: signed variable "ncpus" = "cmax".
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/syst.c:93: negative_returns: 
"ncpus" is passed to a parameter that cannot be negative.

Error: NEGATIVE_RETURNS:
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/self_count.c:192: 
negative_return_fn: Function "sysconf(30)" returns a negative number.
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/self_count.c:192: var_assign: 
Assigning: unsigned variable "pgsz" = "sysconf".
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/self_count.c:214: 
negative_returns: "pgsz" is passed to a parameter that cannot be negative.

Error: NEGATIVE_RETURNS:
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/notify_group.c:148: 
var_tested_neg: Variable "(fds + i).fd" tests negative.
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/notify_group.c:197: 
negative_returns: "(fds + i).fd" is passed to a parameter that cannot be 
negative.

Error: NEGATIVE_RETURNS:
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/notify_self.c:146: 
var_tested_neg: Assigning: "(fds + 0).fd" = a negative value.
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/notify_self.c:180: 
negative_returns: "(fds + 0).fd" is passed to a parameter that cannot be 
negative.

Error: NULL_RETURNS:
/builddir/build/BUILD/libpfm-4.2.0/examples/showevtinfo.c:655: example_assign: 
Assigning: "p" = return value from "strchr(arg, 44)".
/builddir/build/BUILD/libpfm-4.2.0/examples/showevtinfo.c:656: example_checked: 
"p" has its value checked in "p".
/builddir/build/BUILD/libpfm-4.2.0/lib/pfmlib_common.c:471: example_assign: 
Assigning: "p" = return value from "strchr(pfm_cfg.forced_pmu, 44)".
/builddir/build/BUILD/libpfm-4.2.0/lib/pfmlib_common.c:472: example_checked: 
"p" has its value checked in "p".
/builddir/build/BUILD/libpfm-4.2.0/lib/pfmlib_common.c:965: example_assign: 
Assigning: "p" = return value from "strchr(s, 44)".
/builddir/build/BUILD/libpfm-4.2.0/lib/pfmlib_common.c:966: example_checked: 
"p" has its value checked in "p".
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/perf_util.c:127: 
example_checked: "strchr(q, 44)" has its value checked in "p = strchr(q, 44)".
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/perf_util.c:141: 
returned_null: Function "strchr" returns null (checked 4 out of 5 times).
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/perf_util.c:141: var_assigned: 
Assigning: "p" = null return value from "strchr".
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/perf_util.c:142: dereference: 
Dereferencing a null pointer "p".

Error: RESOURCE_LEAK:
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/syst_count.c:323: open_fn: 
Calling opening function "open_cgroup".
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/syst_count.c:122: open_fn: 
Returning handle opened by function "open".
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/syst_count.c:122: var_assign: 
Assigning: "cfd" = "open(path, 0)".
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/syst_count.c:126: 
return_handle: Returning opened handle "cfd".
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/syst_count.c:323: var_assign: 
Assigning: "cfd" =  handle returned from "open_cgroup(options.cgroup_name)".
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/syst_count.c:329: noescape: 
Variable "cfd" is not closed or saved in function "setup_cpu".
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/syst_count.c:382: 
leaked_handle: Handle variable "cfd" going out of scope leaks the handle.

Error: RESOURCE_LEAK:
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/syst_smpl.c:306: open_fn: 
Calling opening function "open_cgroup".
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/syst_smpl.c:278: open_fn: 
Returning handle opened by function "open".
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/syst_smpl.c:278: var_assign: 
Assigning: "cfd" = "open(path, 0)".
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/syst_smpl.c:282: 
return_handle: Returning opened handle "cfd".
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/syst_smpl.c:306: var_assign: 
Assigning: "fd" =  handle returned from "open_cgroup(options.cgroup)".
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/syst_smpl.c:311: noescape: 
Variable "fd" is not closed or saved in function "setup_cpu".
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/syst_smpl.c:350: 
leaked_handle: Handle variable "fd" going out of scope leaks the handle.

Error: RESOURCE_LEAK:
/builddir/build/BUILD/libpfm-4.2.0/python/src/perfmon_int_wrap.c:9825: 
alloc_fn: Calling allocation function "malloc".
/builddir/build/BUILD/libpfm-4.2.0/python/src/perfmon_int_wrap.c:9825: 
var_assign: Assigning: "arg4" =  storage returned from "malloc(64UL)".
/builddir/build/BUILD/libpfm-4.2.0/python/src/perfmon_int_wrap.c:9826: 
noescape: Variable "arg4" is not freed or pointed-to in function "memset".
/builddir/build/BUILD/libpfm-4.2.0/python/src/perfmon_int_wrap.c:9844: 
noescape: Variable "arg4" is not freed or pointed-to in function 
"pfm_get_event_attr_info".
/builddir/build/BUILD/libpfm-4.2.0/lib/pfmlib_common.c:1473:84: noescape: 
"pfm_get_event_attr_info" does not free or save its pointer parameter "uinfo".
/builddir/build/BUILD/libpfm-4.2.0/python/src/perfmon_int_wrap.c:9867: 
leaked_storage: Variable "arg4" going out of scope leaks the storage it points 
to.

Error: RESOURCE_LEAK:
/builddir/build/BUILD/libpfm-4.2.0/python/src/perfmon_int_wrap.c:9609: 
alloc_fn: Calling allocation function "malloc".
/builddir/build/BUILD/libpfm-4.2.0/python/src/perfmon_int_wrap.c:9609: 
var_assign: Assigning: "arg2" =  storage returned from "malloc(56UL)".
/builddir/build/BUILD/libpfm-4.2.0/python/src/perfmon_int_wrap.c:9610: 
noescape: Variable "arg2" is not freed or pointed-to in function "memset".
/builddir/build/BUILD/libpfm-4.2.0/python/src/perfmon_int_wrap.c:9618: 
noescape: Variable "arg2" is not freed or pointed-to in function 
"pfm_get_pmu_info".
/builddir/build/BUILD/libpfm-4.2.0/lib/pfmlib_common.c:1540:51: noescape: 
"pfm_get_pmu_info" does not free or save its pointer parameter "uinfo".
/builddir/build/BUILD/libpfm-4.2.0/python/src/perfmon_int_wrap.c:9641: 
leaked_storage: Variable "arg2" going out of scope leaks the storage it points 
to.

Error: RESOURCE_LEAK:
/builddir/build/BUILD/libpfm-4.2.0/python/src/perfmon_int_wrap.c:9706: 
alloc_fn: Calling allocation function "malloc".
/builddir/build/BUILD/libpfm-4.2.0/python/src/perfmon_int_wrap.c:9706: 
var_assign: Assigning: "arg3" =  storage returned from "malloc(64UL)".
/builddir/build/BUILD/libpfm-4.2.0/python/src/perfmon_int_wrap.c:9707: 
noescape: Variable "arg3" is not freed or pointed-to in function "memset".
/builddir/build/BUILD/libpfm-4.2.0/python/src/perfmon_int_wrap.c:9720: 
noescape: Variable "arg3" is not freed or pointed-to in function 
"pfm_get_event_info".
/builddir/build/BUILD/libpfm-4.2.0/lib/pfmlib_common.c:1415:60: noescape: 
"pfm_get_event_info" does not free or save its pointer parameter "uinfo".
/builddir/build/BUILD/libpfm-4.2.0/python/src/perfmon_int_wrap.c:9743: 
leaked_storage: Variable "arg3" going out of scope leaks the storage it points 
to.

Error: UNINIT:
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/perf_util.c:314: var_decl: 
Declaring variable "time_enabled" without initializer.
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/perf_util.c:555: 
uninit_use_in_call: Using uninitialized value "time_enabled" when calling 
"fprintf".

Error: UNINIT:
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/perf_util.c:314: var_decl: 
Declaring variable "time_running" without initializer.
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/perf_util.c:555: 
uninit_use_in_call: Using uninitialized value "time_running" when calling 
"fprintf".

Error: UNINIT:
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/task_cpu.c:182: var_decl: 
Declaring variable "go" without initializer.
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/task_cpu.c:294: 
uninit_use_in_call: Using uninitialized value "go[1]" when calling "close".

Error: UNINIT:
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/task.c:178: var_decl: 
Declaring variable "go" without initializer.
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/task.c:280: 
uninit_use_in_call: Using uninitialized value "go[1]" when calling "close".

Error: UNINIT:
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/self_count.c:134: var_decl: 
Declaring variable "idx" without initializer.
/builddir/build/BUILD/libpfm-4.2.0/perf_examples/self_count.c:159: 
uninit_use_in_call: Using uninitialized value "idx" when calling "printf".

Error: UNUSED_VALUE:
/builddir/build/BUILD/libpfm-4.2.0/python/src/perfmon_int_wrap.c:2773: 
returned_pointer: Pointer "tmp" returned by "SWIG_Python_str_AsChar(old_str)" 
is never used.

Error: UNUSED_VALUE:
/builddir/build/BUILD/libpfm-4.2.0/python/src/perfmon_int_wrap.c:2775: 
returned_pointer: Pointer "tmp" returned by "SWIG_Python_str_AsChar(old_str)" 
is never used.

Error: UNUSED_VALUE:
/builddir/build/BUILD/libpfm-4.2.0/python/src/perfmon_int_wrap.c:1004: 
returned_pointer: Pointer "tmp" returned by "SWIG_Python_str_AsChar(old_str)" 
is never used.

Error: UNUSED_VALUE:
/builddir/build/BUILD/libpfm-4.2.0/python/src/perfmon_int_wrap.c:10797: 
returned_pointer: Pointer "tmp" returned by "SWIG_Python_str_AsChar(str)" is 
never used.
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
perfmon2-devel mailing list
perfmon2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perfmon2-devel

Reply via email to