{
DIR *topproc_dir;
struct dirent *topproc_dent;
- char *fd_dirpath, *fd_pathname;
struct inode_list *ino_tmp;
struct device_list *dev_tmp;
pid_t pid, my_pid;
uid_t uid;
struct stat *cwd_stat, *exe_stat, *root_stat;
- if ((fd_dirpath = malloc(MAX_PATHNAME)) == NULL)
- return;
- if ((fd_pathname = malloc(MAX_PATHNAME)) == NULL)
- return;
-
if ((topproc_dir = opendir("/proc")) == NULL) {
fprintf(stderr, _("Cannot open /proc directory: %s\n"),
strerror(errno));
}
}
}
+ if (root_stat) free(root_stat);
+ if (cwd_stat) free(cwd_stat);
+ if (exe_stat) free(exe_stat);
check_dir(pid, "lib", dev_head, ino_head, uid, ACCESS_MMAP,
sockets, netdev);
check_dir(pid, "mmap", dev_head, ino_head, uid, ACCESS_MMAP,
{
struct inode_list *ino_tmp, *ino_head;
- ino_head = *ino_list;
-
- if ((ino_tmp = malloc(sizeof(struct inode_list))) == NULL)
+ if ((ino_tmp = (struct inode_list*)malloc(sizeof(struct inode_list))) == NULL)
return;
+ ino_head = *ino_list;
ino_tmp->name = this_name;
ino_tmp->device = device;
ino_tmp->inode = inode;
struct device_list *dev_tmp, *dev_head;
/*printf("Adding device %s %d\n", this_name->filename, device); */
- dev_head = *dev_list;
- if ((dev_tmp = malloc(sizeof(struct device_list))) == NULL)
+ if ((dev_tmp = (struct device_list*)malloc(sizeof(struct device_list))) == NULL)
return;
+ dev_head = *dev_list;
dev_tmp->name = this_name;
dev_tmp->device = device;
dev_tmp->next = dev_head;
{
struct ip_connections *ip_tmp, *ip_head;
- ip_head = *ip_list;
-
- if ((ip_tmp = malloc(sizeof(struct ip_connections))) == NULL)
+ if ((ip_tmp = (struct ip_connections*)malloc(sizeof(struct ip_connections))) == NULL)
return;
+ ip_head = *ip_list;
ip_tmp->name = this_name;
ip_tmp->lcl_port = lcl_port;
ip_tmp->rmt_port = rmt_port;
{
struct ip6_connections *ip_tmp, *ip_head;
- ip_head = *ip_list;
-
- if ((ip_tmp = malloc(sizeof(struct ip6_connections))) == NULL)
+ if ((ip_tmp = (struct ip6_connections*)malloc(sizeof(struct ip6_connections))) == NULL)
return;
+ ip_head = *ip_list;
ip_tmp->name = this_name;
ip_tmp->lcl_port = lcl_port;
ip_tmp->rmt_port = rmt_port;
}
}
/* Not found */
- if ((pptr = malloc(sizeof(struct procs))) == NULL) {
+ if ((pptr = (struct procs*)malloc(sizeof(struct procs))) == NULL) {
fprintf(stderr,
_("Cannot allocate memory for matched proc: %s\n"),
strerror(errno));
pptr->next = NULL;
/* set command name */
pptr->command = NULL;
+
+ fp = NULL;
+ pathname = NULL;
if ((asprintf(&pathname, "/proc/%d/stat", pid) > 0) &&
((fp = fopen(pathname, "r")) != NULL) &&
(fscanf(fp, "%*d (%100[^)]", cmdname) == 1))
- if ((pptr->command = malloc(MAX_CMDNAME + 1)) != NULL) {
+ if ((pptr->command = (char*)malloc(MAX_CMDNAME + 1)) != NULL) {
cmdlen = 0;
for (cptr = cmdname; cmdlen < MAX_CMDNAME && *cptr;
cptr++) {
name_list->matched_procs = pptr;
else
last_proc->next = pptr;
+ if (pathname)
+ free(pathname);
+ if (fp)
+ fclose(fp);
}
/* Adds a knfsd etc process */
}
}
- return;
+ fclose(fp);
}
#ifdef WITH_IPV6
}
}
}
+ fclose(fp);
}
#endif
char pathname[256];
struct stat *st;
- if ((st = malloc(sizeof(struct stat))) == NULL)
+ if ((st = (struct stat*)malloc(sizeof(struct stat))) == NULL)
return NULL;
snprintf(pathname, 256, "/proc/%d/%s", pid, filename);
if (stat(pathname, st) != 0)
- return NULL;
- else
- return st;
+ goto out;
+ return st;
+out:
+ free(st);
+ return NULL;
}
static void
struct inode_list *ino_head, const uid_t uid, const char access,
struct unixsocket_list *sockets, dev_t netdev)
{
- char *dirpath, *filepath;
+ char *dirpath = NULL, *filepath = NULL;
DIR *dirp;
struct dirent *direntry;
struct inode_list *ino_tmp;
struct unixsocket_list *sock_tmp;
struct stat st, lst;
- if ((dirpath = malloc(MAX_PATHNAME)) == NULL)
- return;
- if ((filepath = malloc(MAX_PATHNAME)) == NULL)
- return;
+ if ((dirpath = (char*)malloc(MAX_PATHNAME)) == NULL)
+ goto out;
+ if ((filepath = (char*)malloc(MAX_PATHNAME)) == NULL)
+ goto out;
snprintf(dirpath, MAX_PATHNAME, "/proc/%d/%s", pid, dirname);
if ((dirp = opendir(dirpath)) == NULL)
- return;
+ goto out;
while ((direntry = readdir(dirp)) != NULL) {
if (direntry->d_name[0] < '0' || direntry->d_name[0] > '9')
continue;
}
} /* while fd_dent */
closedir(dirp);
+out:
+ if (dirpath)
+ free(dirpath);
+ if (filepath)
+ free(filepath);
}
static void
{
FILE *fp;
char line[BUFSIZ];
- char *scanned_path;
int scanned_inode;
struct stat st;
struct unixsocket_list *newsocket;
return;
}
while (fgets(line, BUFSIZ, fp) != NULL) {
+ char * path;
+ char * scanned_path = NULL;
if (sscanf(line, "%*x: %*x %*x %*x %*x %*d %d %as",
- &scanned_inode, &scanned_path) != 2)
+ &scanned_inode, &scanned_path) != 2) {
+ if (scanned_path)
+ free(scanned_path);
continue;
+ }
+ if (scanned_path == NULL)
+ continue;
+ path = scanned_path;
+ if (*scanned_path == '@')
+ scanned_path++;
if (stat(scanned_path, &st) < 0) {
- free(scanned_path);
+ free(path);
continue;
}
- if ((newsocket =
- malloc(sizeof(struct unixsocket_list))) == NULL)
+ if ((newsocket = (struct unixsocket_list*)
+ malloc(sizeof(struct unixsocket_list))) == NULL) {
+ free(path);
continue;
+ }
newsocket->sun_name = strdup(scanned_path);
newsocket->inode = st.st_ino;
newsocket->dev = st.st_dev;
newsocket->net_inode = scanned_inode;
newsocket->next = *unixsocket_head;
*unixsocket_head = newsocket;
+ free(path);
} /* while */
+ fclose(fp);
}
#ifdef DEBUG
line);
}
}
+ fclose(fp);
}
static void
find_mountp);
}
}
+ fclose(fp);
}
static void
line);
}
}
+ fclose(fp);
}