1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-01-27 09:08:25 +00:00

Fix memleak and change literals to defines

This commit is contained in:
Nikolas Garofil 2009-11-11 13:23:05 +01:00
parent 8276da8777
commit 65cf0439a0
3 changed files with 12 additions and 8 deletions

View File

@ -645,7 +645,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
#endif
END OBJ(nodename, 0)
END OBJ_ARG(pid, 0, "pid needs arguments")
scan_pid_arg(obj, arg);
scan_pid_arg(obj, arg, free_at_crash);
END OBJ(processes, &update_total_processes)
END OBJ(running_processes, &update_running_processes)
END OBJ(threads, &update_threads)

View File

@ -30,19 +30,19 @@
#include <logging.h>
#include "conky.h"
#include "proc.h"
#define PROCDIR "/proc"
void scan_pid_arg(struct text_object *obj, const char *arg)
void scan_pid_arg(struct text_object *obj, const char *arg, void* free_at_crash)
{
char* string = strdup(arg);
pid_t pid;
if(sscanf(arg, "%s %d", string, &pid) == 2 && strcasecmp(string, "cmdline") == 0) {
asprintf(&obj->data.s, "/proc/%d/%s", pid, string);
asprintf(&obj->data.s, PROCDIR "/%d/%s", pid, string);
free(string);
} else {
CRIT_ERR(string, NULL, "${proc cmdline <pid>}");
free(string);
CRIT_ERR(obj, free_at_crash, PID_SYNTAXERR);
}
}
@ -63,6 +63,6 @@ void print_pid(struct text_object *obj, char *p, int p_max_size)
snprintf(p, p_max_size, "%s", buf);
fclose(infofile);
} else {
NORM_ERR("Can't read %s", obj->data.s);
NORM_ERR(READERR, obj->data.s);
}
}

View File

@ -28,5 +28,9 @@
*
*/
void scan_pid_arg(struct text_object *, const char *);
#define PROCDIR "/proc"
#define PID_SYNTAXERR "${pid cmdline <pid>}"
#define READERR "Can't read '%s'"
void scan_pid_arg(struct text_object *, const char *, void* free_at_crash);
void print_pid(struct text_object *, char *, int);