mirror of
https://github.com/javalsai/lidm.git
synced 2025-07-03 06:15:03 +02:00
fix: memory leaks
This commit is contained in:
parent
04a102a7bb
commit
b22ae6b2cc
@ -125,6 +125,7 @@ static int fn(const char *fpath, const struct stat *sb, int typeflag) {
|
||||
// This code is designed to be run purely single threaded
|
||||
struct Vector get_avaliable_sessions() {
|
||||
struct Vector sessions = vec_new();
|
||||
vec_reserve(&sessions, 8);
|
||||
|
||||
cb_sessions = &sessions;
|
||||
for (size_t i = 0; i < (sizeof(sources) / sizeof(sources[0])); i++) {
|
||||
|
7
src/ui.c
7
src/ui.c
@ -322,6 +322,7 @@ void ffield_type(char *text) {
|
||||
print_ffield();
|
||||
}
|
||||
|
||||
static char* unknown_str = "unknown";
|
||||
int load(struct Vector *users, struct Vector *sessions) {
|
||||
/// SETUP
|
||||
gusers = users;
|
||||
@ -331,9 +332,9 @@ int load(struct Vector *users, struct Vector *sessions) {
|
||||
char *hostname = malloc(16);
|
||||
if (gethostname(hostname, 16) != 0) {
|
||||
free(hostname);
|
||||
hostname = "unknown";
|
||||
hostname = unknown_str;
|
||||
} else {
|
||||
hostname = realloc(hostname, strlen(hostname) + 1);
|
||||
hostname[15] = '\0';
|
||||
}
|
||||
|
||||
of_session = ofield_new(sessions->length + behavior.include_defshell);
|
||||
@ -350,12 +351,14 @@ int load(struct Vector *users, struct Vector *sessions) {
|
||||
printf("\x1b[%d;%dH\x1b[%sm%s\x1b[%sm", boxstart.y + 2,
|
||||
boxstart.x + 12 - (uint)strlen(hostname), theme.colors.e_hostname,
|
||||
hostname, theme.colors.fg);
|
||||
if(hostname != unknown_str) free(hostname);
|
||||
|
||||
// put date
|
||||
char *fmtd_time = fmt_time();
|
||||
printf("\x1b[%d;%dH\x1b[%sm%s\x1b[%sm", boxstart.y + 2,
|
||||
boxstart.x + boxw - 3 - (uint)strlen(fmtd_time), theme.colors.e_date,
|
||||
fmtd_time, theme.colors.fg);
|
||||
free(fmtd_time);
|
||||
|
||||
print_field(SESSION);
|
||||
print_field(USER);
|
||||
|
@ -23,6 +23,7 @@ static struct user __new_user(struct passwd *p) {
|
||||
// This code is designed to be run purely single threaded
|
||||
struct Vector get_human_users() {
|
||||
struct Vector users = vec_new();
|
||||
vec_reserve(&users, 4);
|
||||
|
||||
struct passwd *pwd;
|
||||
while ((pwd = getpwent()) != NULL) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user