Skip to content

Commit

Permalink
set null to a few dangling pointers i forgot
Browse files Browse the repository at this point in the history
  • Loading branch information
constarg committed Dec 21, 2023
1 parent eb14c0b commit aebf2d8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/lkby_discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,15 @@ static void read_keyboards(FILE *devices)
if (NULL == (kb_name = retrieve_keyboard_name(dev))) {
free(kb_event);
free(dev);
dev = NULL;
dev = NULL;
kb_event = NULL;
continue;
}
store_kb_to_transmit_queue((const char *) kb_event,
(const char *) kb_name);
}
free(dev);
dev = NULL;
}
// inform the scheduler thread that there are keyboards in the queue.
(void)sem_post(&LKBYQUEUE_SEM(&g_keyboard_queue));
Expand Down
5 changes: 3 additions & 2 deletions src/lkby_scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static inline int add_active_kb(const struct active_kb *src)
* @param src The keyboard to remove.
* @return 0 on success, otherwise -1.
**/
static int remove_active_kb(struct active_kb *restrict src)
static int remove_active_kb(struct active_kb *src)
{
int index = -1;
for (size_t i = 0; i < g_active_next; i++) {
Expand All @@ -106,6 +106,7 @@ static int remove_active_kb(struct active_kb *restrict src)
lkby_keyboard_free(&LKBYACTIVE_KB(src));
// free the previous allocated active_keyboard.
free(src);
src = NULL;
--g_active_next;

if (g_s_active_kbs - g_active_next > 10) {
Expand Down Expand Up @@ -230,6 +231,7 @@ static void *keyboard_routine(void *src)

keyboard_routine_failed_label:
free(absolute_path_to_event);
absolute_path_to_event = NULL;
(void)close(event_fd);
pthread_cleanup_pop(1);
return NULL;
Expand Down Expand Up @@ -285,7 +287,6 @@ void *lkby_start_scheduler(void *none __attribute__((unused)))
(void)pthread_detach(ac_kb->kb_thread);

continue; // ! DO NOT GO TO THE ARREA OF ERRORS. (label below).
// TODO - this error handling need more tests.
lkby_scheduler_failed_label:
free(kb);
free(ac_kb);
Expand Down

0 comments on commit aebf2d8

Please sign in to comment.