Browse Source

Refine ss_align interfaces

pull/2274/head
Max Lv 6 years ago
parent
commit
782311ad2b
7 changed files with 21 additions and 13 deletions
  1. 4
      src/aead.c
  2. 4
      src/local.c
  3. 4
      src/redir.c
  4. 4
      src/server.c
  5. 4
      src/tunnel.c
  6. 11
      src/utils.c
  7. 3
      src/utils.h

4
src/aead.c

@ -331,7 +331,7 @@ aead_cipher_ctx_init(cipher_ctx_t *cipher_ctx, int method, int enc)
const cipher_kt_t *cipher = aead_get_cipher_type(method);
if (method == AES256GCM && crypto_aead_aes256gcm_is_available()) {
cipher_ctx->aes256gcm_ctx = ss_align(sizeof(aes256gcm_ctx));
cipher_ctx->aes256gcm_ctx = ss_aligned_malloc(sizeof(aes256gcm_ctx));
memset(cipher_ctx->aes256gcm_ctx, 0, sizeof(aes256gcm_ctx));
} else {
cipher_ctx->aes256gcm_ctx = NULL;
@ -382,7 +382,7 @@ aead_ctx_release(cipher_ctx_t *cipher_ctx)
}
if (cipher_ctx->aes256gcm_ctx != NULL) {
ss_free(cipher_ctx->aes256gcm_ctx);
ss_aligned_free(cipher_ctx->aes256gcm_ctx);
return;
}

4
src/local.c

@ -1246,8 +1246,8 @@ new_server(int fd)
server->recv_ctx->server = server;
server->send_ctx->server = server;
server->e_ctx = ss_align(sizeof(cipher_ctx_t));
server->d_ctx = ss_align(sizeof(cipher_ctx_t));
server->e_ctx = ss_malloc(sizeof(cipher_ctx_t));
server->d_ctx = ss_malloc(sizeof(cipher_ctx_t));
crypto->ctx_init(crypto->cipher, server->e_ctx, 1);
crypto->ctx_init(crypto->cipher, server->d_ctx, 0);

4
src/redir.c

@ -650,8 +650,8 @@ new_server(int fd)
server->send_ctx->server = server;
server->send_ctx->connected = 0;
server->e_ctx = ss_align(sizeof(cipher_ctx_t));
server->d_ctx = ss_align(sizeof(cipher_ctx_t));
server->e_ctx = ss_malloc(sizeof(cipher_ctx_t));
server->d_ctx = ss_malloc(sizeof(cipher_ctx_t));
crypto->ctx_init(crypto->cipher, server->e_ctx, 1);
crypto->ctx_init(crypto->cipher, server->d_ctx, 0);

4
src/server.c

@ -1415,8 +1415,8 @@ new_server(int fd, listen_ctx_t *listener)
server->listen_ctx = listener;
server->remote = NULL;
server->e_ctx = ss_align(sizeof(cipher_ctx_t));
server->d_ctx = ss_align(sizeof(cipher_ctx_t));
server->e_ctx = ss_malloc(sizeof(cipher_ctx_t));
server->d_ctx = ss_malloc(sizeof(cipher_ctx_t));
crypto->ctx_init(crypto->cipher, server->e_ctx, 1);
crypto->ctx_init(crypto->cipher, server->d_ctx, 0);

4
src/tunnel.c

@ -664,8 +664,8 @@ new_server(int fd)
server->send_ctx->server = server;
server->send_ctx->connected = 0;
server->e_ctx = ss_align(sizeof(cipher_ctx_t));
server->d_ctx = ss_align(sizeof(cipher_ctx_t));
server->e_ctx = ss_malloc(sizeof(cipher_ctx_t));
server->d_ctx = ss_malloc(sizeof(cipher_ctx_t));
crypto->ctx_init(crypto->cipher, server->e_ctx, 1);
crypto->ctx_init(crypto->cipher, server->d_ctx, 0);

11
src/utils.c

@ -243,7 +243,7 @@ ss_malloc(size_t size)
}
void *
ss_align(size_t size)
ss_aligned_malloc(size_t size)
{
int err;
void *tmp = NULL;
@ -264,7 +264,7 @@ ss_align(size_t size)
}
void
ss_free(void *ptr)
ss_aligned_free(void *ptr)
{
#ifdef __MINGW32__
_aligned_free(ptr);
@ -274,6 +274,13 @@ ss_free(void *ptr)
ptr = NULL;
}
void
ss_free(void *ptr)
{
free(ptr);
ptr = NULL;
}
void *
ss_realloc(void *ptr, size_t new_size)
{

3
src/utils.h

@ -227,8 +227,9 @@ int set_nofile(int nofile);
#endif
void *ss_malloc(size_t size);
void *ss_align(size_t size);
void *ss_aligned_malloc(size_t size);
void *ss_realloc(void *ptr, size_t new_size);
void ss_aligned_free(void *ptr);
void ss_free(void *ptr);
int ss_is_ipv6addr(const char *addr);

Loading…
Cancel
Save