mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-10 14:42:08 +03:00
Use free followed by malloc instead of realloc when increasing raw buffer
At this point we don't need to preserve the data inside the buffer. Using free followed by malloc reduces fragmentation for some heap implementations.
This commit is contained in:
16
ssl/tls1.c
16
ssl/tls1.c
@ -1402,15 +1402,19 @@ error:
|
||||
|
||||
void increase_bm_data_size(SSL *ssl)
|
||||
{
|
||||
uint8_t* pr = (uint8_t*) realloc(ssl->bm_all_data, RT_MAX_PLAIN_LENGTH + RT_EXTRA);
|
||||
if (pr) {
|
||||
ssl->max_plain_length = RT_MAX_PLAIN_LENGTH;
|
||||
ssl->bm_all_data = pr;
|
||||
ssl->bm_data = pr + BM_RECORD_OFFSET;
|
||||
if (ssl->max_plain_length == RT_MAX_PLAIN_LENGTH) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
|
||||
free(ssl->bm_all_data);
|
||||
ssl->bm_data = 0;
|
||||
ssl->bm_all_data = malloc(RT_MAX_PLAIN_LENGTH + RT_EXTRA);
|
||||
if (!ssl->bm_all_data) {
|
||||
printf("failed to grow plain buffer\r\n");
|
||||
return;
|
||||
}
|
||||
ssl->max_plain_length = RT_MAX_PLAIN_LENGTH;
|
||||
ssl->bm_data = ssl->bm_all_data + BM_RECORD_OFFSET;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user