mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-02-11 00:18:29 +00:00
Fix memleak and change literals to defines
This commit is contained in:
parent
8276da8777
commit
65cf0439a0
@ -645,7 +645,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
|||||||
#endif
|
#endif
|
||||||
END OBJ(nodename, 0)
|
END OBJ(nodename, 0)
|
||||||
END OBJ_ARG(pid, 0, "pid needs arguments")
|
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(processes, &update_total_processes)
|
||||||
END OBJ(running_processes, &update_running_processes)
|
END OBJ(running_processes, &update_running_processes)
|
||||||
END OBJ(threads, &update_threads)
|
END OBJ(threads, &update_threads)
|
||||||
|
12
src/proc.c
12
src/proc.c
@ -30,19 +30,19 @@
|
|||||||
|
|
||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
#include "conky.h"
|
#include "conky.h"
|
||||||
|
#include "proc.h"
|
||||||
|
|
||||||
#define PROCDIR "/proc"
|
void scan_pid_arg(struct text_object *obj, const char *arg, void* free_at_crash)
|
||||||
|
|
||||||
void scan_pid_arg(struct text_object *obj, const char *arg)
|
|
||||||
{
|
{
|
||||||
char* string = strdup(arg);
|
char* string = strdup(arg);
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
if(sscanf(arg, "%s %d", string, &pid) == 2 && strcasecmp(string, "cmdline") == 0) {
|
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);
|
free(string);
|
||||||
} else {
|
} 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);
|
snprintf(p, p_max_size, "%s", buf);
|
||||||
fclose(infofile);
|
fclose(infofile);
|
||||||
} else {
|
} else {
|
||||||
NORM_ERR("Can't read %s", obj->data.s);
|
NORM_ERR(READERR, obj->data.s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
void print_pid(struct text_object *, char *, int);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user