Skip to content

Commit

Permalink
fixed some memleaks
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed Oct 6, 2024
1 parent b40626a commit ca0cb7b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/app/backend/pcmanager/discovery/impl/microdns.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void discovery_callback(discovery_task_t *task, int status, const struct rr_entr
return;
}
if (task->stop) { return; }
struct sockaddr *addr = sockaddr_new();
sockaddr_t *addr = sockaddr_new();
for (const struct rr_entry *cur = entries; cur != NULL; cur = cur->next) {
switch (cur->type) {
case RR_A: {
Expand All @@ -87,10 +87,10 @@ void discovery_callback(discovery_task_t *task, int status, const struct rr_entr
}
}
}
if (addr->sa_family == AF_UNSPEC) {
return;
if (addr->sa_family != AF_UNSPEC) {
discovery_discovered(task->discovery, addr);
}
discovery_discovered(task->discovery, addr);
sockaddr_free(addr);
}

bool discovery_is_stopped(discovery_task_t *task) {
Expand Down
11 changes: 9 additions & 2 deletions src/app/backend/pcmanager/discovery/throttle.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ static int throttle_hosts_find_not_expired(discovery_throttle_host_t *node, cons

static void throttle_hosts_evict(discovery_throttle_host_t **head);

static void throttle_host_free(discovery_throttle_host_t *node);

void discovery_throttle_init(discovery_throttle_t *throttle, discovery_callback callback, void *user_data) {
throttle->callback = callback;
throttle->user_data = user_data;
Expand All @@ -56,7 +58,7 @@ void discovery_throttle_init(discovery_throttle_t *throttle, discovery_callback

void discovery_throttle_deinit(discovery_throttle_t *throttle) {
SDL_LockMutex(throttle->lock);
throttle_hosts_free(throttle->hosts, NULL);
throttle_hosts_free(throttle->hosts, throttle_host_free);
SDL_UnlockMutex(throttle->lock);
SDL_DestroyMutex(throttle->lock);
}
Expand All @@ -82,7 +84,7 @@ void discovery_throttle_on_discovered(discovery_throttle_t *throttle, const sock
throttle->hosts = throttle_hosts_sortedinsert(throttle->hosts, node, throttle_hosts_compare_time);

if (throttle->callback != NULL) {
throttle->callback(addr, throttle->user_data);
throttle->callback(node->addr, throttle->user_data);
}
SDL_UnlockMutex(throttle->lock);
}
Expand Down Expand Up @@ -112,3 +114,8 @@ void throttle_hosts_evict(discovery_throttle_host_t **head) {
int throttle_hosts_find_not_expired(discovery_throttle_host_t *node, const void *now) {
return SDL_TICKS_PASSED(*(Uint32 *) now, node->last_discovered + node->ttl);
}

void throttle_host_free(discovery_throttle_host_t *node) {
sockaddr_free(node->addr);
free(node);
}

0 comments on commit ca0cb7b

Please sign in to comment.