Re: [PATCH] Fixes for coverity reported issues in opagent.c
Maynard Johnson <[email protected]>
| Newsgroups | gmane.linux.oprofile |
|---|---|
| Message-ID | <[email protected]> |
On 07/25/2014 02:28 PM, William Cohen wrote:
> The patch fixes the following errors: :
Will, thanks for the coverity report. As a matter of fact, running coverity is one of the tasks listed on our release checklist (oprofile-www/releasechecklist), so I'll run it again right before putting out the release candidate.
The patch below looks fine, so go ahead and commit it.
-Maynard
>
> Error: COMPILER_WARNING:
> oprofile-1.0.0git/libopagent/opagent.c: scope_hint: In function 'op_open_agent'
> oprofile-1.0.0git/libopagent/opagent.c:205:2: warning: implicit declaration of function 'flock' [-Wimplicit-function-declaration]
> rc = flock(fd, LOCK_EX | LOCK_NB);
> ^
>
> Error: RESOURCE_LEAK (CWE-772):
> oprofile-1.0.0git/libopagent/opagent.c:195: alloc_fn: Storage is returned from allocation function "fdopen(int, char const *)".
> oprofile-1.0.0git/libopagent/opagent.c:195: var_assign: Assigning: "dumpfile" = storage returned from "fdopen(fd, "w")".
> oprofile-1.0.0git/libopagent/opagent.c:213: leaked_storage: Variable "dumpfile" going out of scope leaks the storage it points to.
>
> Error: UNINIT (CWE-457):
> oprofile-1.0.0git/libopagent/opagent.c:266: var_decl: Declaring variable "dumpfd" without initializer.
> oprofile-1.0.0git/libopagent/opagent.c:285: uninit_use_in_call: Using uninitialized value "dumpfd" when calling "flock()".
>
> Error: COMPILER_WARNING:
> oprofile-1.0.0git/libopagent/opagent.c: scope_hint: In function 'op_close_agent'
> oprofile-1.0.0git/libopagent/opagent.c:285:5: warning: 'dumpfd' may be used uninitialized in this function [-Wmaybe-uninitialized]
> rc = flock(dumpfd, LOCK_EX | LOCK_NB);
> ^
> ---
> libopagent/opagent.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/libopagent/opagent.c b/libopagent/opagent.c
> index 0d97265..c38d7df 100644
> --- a/libopagent/opagent.c
> +++ b/libopagent/opagent.c
> @@ -63,6 +63,7 @@
> #include <unistd.h>
> #include <time.h>
> #include <bfd.h>
> +#include <sys/file.h>
>
> #include "opagent.h"
> #include "op_config.h"
> @@ -210,6 +211,7 @@ again:
> goto again;
> } else {
> printf("opagent: Unable to obtain lock on JIT dumpfile\n");
> + fclose(dumpfile);
> return NULL;
> }
> }
> @@ -279,6 +281,10 @@ int op_close_agent(op_agent_t hdl)
> }
> rec.timestamp = tv.tv_sec;
>
> + if ((dumpfd = fileno(dumpfile)) < 0) {
> + fprintf(stderr, "opagent: Unable to get file descriptor for JIT dumpfile\n");
> + return -1;
> + }
> again:
> /* We need OS-level file locking here because the opjitconv process may need to
> * copy the dumpfile while the JIT agent is still writing to it. */
>
------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls.
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk