fix: memory leaks

This commit is contained in:
javalsai 2025-06-06 19:39:55 +02:00
parent 04a102a7bb
commit b22ae6b2cc
Signed by: javalsai
SSH Key Fingerprint: SHA256:3G83yKhBUWVABVX/vPWH88xnK4+ptMtHkZGCRXD4Mk8
3 changed files with 7 additions and 2 deletions

View File

@ -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++) {

View File

@ -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);

View File

@ -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) {