Bug #386

Minor cleanups to ./cgi/cgiutils.c

Added by snakebyte almost 4 years ago. Updated almost 4 years ago.

Status:ResolvedStart date:04/29/2010
Priority:LowDue date:
Assignee:dnsmichi% Done:

100%

Category:Other
Target version:1.0.2
Icinga Version: OS Version:

Description

hi,

there are two unused variables (found and statbuf) as well
as a memory leak (daemon_name is only used once, never freed)
and a descriptor leak (fp never gets closed)

Regards, Eric

--- icinga-core/cgi/cgiutils.c.orig 2010-04-29 16:53:46.000000000 0200
++ icinga-core/cgi/cgiutils.c 2010-04-29 16:56:39.000000000 0200
@ -2291,9 +2291,7 @ int check_daemon_running(void) {
char *proc_file=NULL;
char *input = NULL;
char *val = NULL;
- char *daemon_name = NULL;
- struct stat statbuf;
- int pid, testpid, found;
int pid, testpid;
char input_buffer[CHARLEN];
mmapfile *fk;
FILE *fp;
@ -2306,9 +2304,7 @ int check_daemon_running(void) {
if((fk=mmap_fopen(lock_file))==NULL) {

/* no lock file found try program name instead */
- asprintf(&daemon_name,"%s",PROGRAM_NAME_LC);

if(asprintf(&proc_file,"/bin/ps -o pid -C %s",daemon_name)==-1) {
+ if(asprintf(&proc_file,"/bin/ps -o pid -C %s",PROGRAM_NAME_LC)==-1) {
free(proc_file);
return ERROR;
}
@ -2321,13 +2317,14 @ int check_daemon_running(void) {
fgets(input_buffer,CHARLEN-1,fp);
fgets(input_buffer,CHARLEN-1,fp);

+ pclose(fp);
+ free(proc_file);
+
/* check if entry found /
if (sscanf(input_buffer,"%d",&testpid)!=1) {
- free(proc_file);
return ERROR;
} else {
/
daemon is running */
- free(proc_file);
return OK;
}
}

cgiutils.diff Magnifier (1.35 KB) snakebyte, 04/29/2010 04:59 pm


Related issues

Related to Core - Bug #395: Janitor patch: Remove unused variables Resolved 04/30/2010

Associated revisions

Revision b8de14a3
Added by dnsmichi almost 4 years ago

minor cleanups to cgiutils.c (Eric Sesterhenn)

fixes #386

Revision ee0ab2d4
Added by dnsmichi almost 4 years ago

minor cleanups to cgiutils.c (Eric Sesterhenn)

fixes #386

History

#1 Updated by dnsmichi almost 4 years ago

  • Assignee set to dnsmichi
  • Target version set to 1.0.2

#2 Updated by dnsmichi almost 4 years ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 100

Also available in: Atom PDF