Skip to content

Commit

Permalink
#164 cap_lines free method
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-courtis committed Nov 9, 2024
1 parent be9f674 commit 709094a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 23 deletions.
5 changes: 2 additions & 3 deletions inc/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ void log_cap_lines_start(struct SList **log_cap_lines);

void log_cap_lines_stop(struct SList **log_cap_lines);

void log_cap_lines_free(struct SList **log_cap_lines);

void log_cap_lines_playback(struct SList *log_cap_lines);

void log_cap_lines_write(struct SList **log_cap_lines, const char *path);


void log_cap_line_free(void *log_cap_line);

#endif // LOG_H

5 changes: 3 additions & 2 deletions src/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ void ipc_response_free(void *vresponse) {
cfg_free(response->cfg);
lid_free(response->lid);
slist_free_vals(&response->heads, head_free);
slist_free_vals(&response->log_cap_lines, log_cap_line_free);

log_cap_lines_free(&response->log_cap_lines);

free(response);
}
Expand All @@ -132,7 +133,7 @@ void ipc_operation_free(struct IpcOperation *operation) {

log_cap_lines_stop(&operation->log_cap_lines);

slist_free_vals(&operation->log_cap_lines, log_cap_line_free);
log_cap_lines_free(&operation->log_cap_lines);

free(operation);
}
Expand Down
3 changes: 1 addition & 2 deletions src/layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,7 @@ void apply(void) {
// TODO unique file passed to the user
log_cap_lines_stop(&log_cap_lines);
log_cap_lines_write(&log_cap_lines, "/tmp/wd.delta");

slist_free_vals(&log_cap_lines, log_cap_line_free);
log_cap_lines_free(&log_cap_lines);

// all changes except mode
for (i = heads_changing; i; i = i->nex) {
Expand Down
32 changes: 18 additions & 14 deletions src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,20 @@ void log_suppress_stop(void) {
active.suppressing = false;
}

void log_cap_line_free(void *data) {
struct LogCapLine *line = data;

if (!line) {
return;
}

if (line->line) {
free(line->line);
}

free(line);
}

void log_cap_lines_playback(struct SList *lines) {
if (!lines)
return;
Expand All @@ -208,6 +222,10 @@ void log_cap_lines_stop(struct SList **lines) {
slist_remove_all(&log_cap_lines_active, NULL, lines);
}

void log_cap_lines_free(struct SList **lines) {
slist_free_vals(lines, log_cap_line_free);
}

void log_cap_lines_write(struct SList **lines, const char *path) {

// write empty to clear and validate
Expand All @@ -221,17 +239,3 @@ void log_cap_lines_write(struct SList **lines, const char *path) {
}
}

void log_cap_line_free(void *data) {
struct LogCapLine *line = data;

if (!line) {
return;
}

if (line->line) {
free(line->line);
}

free(line);
}

2 changes: 1 addition & 1 deletion src/marshalling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ char *marshal_ipc_response(struct IpcOperation *operation) {
}

// clear marshalled messages
slist_free_vals(&operation->log_cap_lines, log_cap_line_free);
log_cap_lines_free(&operation->log_cap_lines);

return yaml;
}
Expand Down
2 changes: 1 addition & 1 deletion src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ server(char *cfg_path) {
log_suppress_stop();
log_cap_lines_stop(&log_cap_lines);
log_cap_lines_playback(log_cap_lines);
slist_free_vals(&log_cap_lines, log_cap_line_free);
log_cap_lines_free(&log_cap_lines);

// discover the lid state immediately
lid_init();
Expand Down

0 comments on commit 709094a

Please sign in to comment.