mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Use heap memory instead of stack for large variables
The default stack size for musl-libc is 128kb. Therefore we should try to keep stack allocations well below this limit in order to avoid stack overflows.
This commit is contained in:
parent
5d2b1e3861
commit
00f2f41dbb
|
@ -1 +1 @@
|
||||||
16d62d5c5aa261d6efefbe8e94cc25a68c76ea923ae92ce56b0d22b32326ae0b /usr/local/bin/tox-bootstrapd
|
ca03a05f92fb3169c588ff0894c7a1d4466d71c36e3a7ddbe804797f15d6c126 /usr/local/bin/tox-bootstrapd
|
||||||
|
|
|
@ -123,10 +123,15 @@ void ac_iterate(ACSession *ac)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO(mannol): fix this and jitter buffering */
|
/* TODO: fix this and jitter buffering */
|
||||||
|
|
||||||
/* Enough space for the maximum frame size (120 ms 48 KHz stereo audio) */
|
/* Enough space for the maximum frame size (120 ms 48 KHz stereo audio) */
|
||||||
int16_t temp_audio_buffer[AUDIO_MAX_BUFFER_SIZE_PCM16 * AUDIO_MAX_CHANNEL_COUNT];
|
int16_t *temp_audio_buffer = (int16_t *)malloc(AUDIO_MAX_BUFFER_SIZE_PCM16 * AUDIO_MAX_CHANNEL_COUNT * sizeof(int16_t));
|
||||||
|
|
||||||
|
if (temp_audio_buffer == nullptr) {
|
||||||
|
LOGGER_ERROR(ac->log, "Failed to allocate memory for audio buffer");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
pthread_mutex_lock(ac->queue_mutex);
|
pthread_mutex_lock(ac->queue_mutex);
|
||||||
struct JitterBuffer *const j_buf = (struct JitterBuffer *)ac->j_buf;
|
struct JitterBuffer *const j_buf = (struct JitterBuffer *)ac->j_buf;
|
||||||
|
@ -195,10 +200,14 @@ void ac_iterate(ACSession *ac)
|
||||||
ac->lp_sampling_rate, ac->acb_user_data);
|
ac->lp_sampling_rate, ac->acb_user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(temp_audio_buffer);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(ac->queue_mutex);
|
pthread_mutex_unlock(ac->queue_mutex);
|
||||||
|
|
||||||
|
free(temp_audio_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ac_queue_message(Mono_Time *mono_time, void *acp, struct RTPMessage *msg)
|
int ac_queue_message(Mono_Time *mono_time, void *acp, struct RTPMessage *msg)
|
||||||
|
|
|
@ -2830,7 +2830,12 @@ void dht_save(const DHT *dht, uint8_t *data)
|
||||||
/* get right offset. we write the actual header later. */
|
/* get right offset. we write the actual header later. */
|
||||||
data = state_write_section_header(data, DHT_STATE_COOKIE_TYPE, 0, 0);
|
data = state_write_section_header(data, DHT_STATE_COOKIE_TYPE, 0, 0);
|
||||||
|
|
||||||
Node_format clients[MAX_SAVED_DHT_NODES];
|
Node_format *clients = (Node_format *)malloc(MAX_SAVED_DHT_NODES * sizeof(Node_format));
|
||||||
|
|
||||||
|
if (clients == nullptr) {
|
||||||
|
LOGGER_ERROR(dht->log, "could not allocate %u nodes", MAX_SAVED_DHT_NODES);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t num = 0;
|
uint32_t num = 0;
|
||||||
|
|
||||||
|
@ -2873,6 +2878,8 @@ void dht_save(const DHT *dht, uint8_t *data)
|
||||||
|
|
||||||
state_write_section_header(old_data, DHT_STATE_COOKIE_TYPE, pack_nodes(data, sizeof(Node_format) * num, clients, num),
|
state_write_section_header(old_data, DHT_STATE_COOKIE_TYPE, pack_nodes(data, sizeof(Node_format) * num, clients, num),
|
||||||
DHT_STATE_TYPE_NODES);
|
DHT_STATE_TYPE_NODES);
|
||||||
|
|
||||||
|
free(clients);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Bootstrap from this number of nodes every time dht_connect_after_load() is called */
|
/* Bootstrap from this number of nodes every time dht_connect_after_load() is called */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user