1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-13 13:01:55 +03:00

fixed memory leak

git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@63 9a5d90b5-6617-0410-8a86-bb477d3ed2e3
This commit is contained in:
cameronrich
2007-02-18 08:14:01 +00:00
parent 61fd249441
commit 900b0eb96e
12 changed files with 100 additions and 84 deletions

View File

@ -52,13 +52,8 @@ int get_file(const char *filename, uint8_t **buf)
int total_bytes = 0;
int bytes_read = 0;
int filesize;
FILE *stream = fopen(filename, "rb");
FILE *stream = ax_fopen(filename, "rb");
if (stream == NULL)
{
return -1;
}
/* Win CE doesn't support stat() */
fseek(stream, 0, SEEK_END);
filesize = ftell(stream);
@ -87,11 +82,7 @@ EXP_FUNC void STDCALL RNG_initialize(const uint8_t *seed_buf, int size)
if (rng_ref_count == 0)
{
#if !defined(WIN32) && defined(CONFIG_USE_DEV_URANDOM)
if ((rng_fd = open("/dev/urandom", O_RDONLY)) < 0)
{
printf(unsupported_str);
exit(1);
}
rng_fd = ax_open("/dev/urandom", O_RDONLY);
#elif defined(WIN32) && defined(CONFIG_WIN32_USE_CRYPTO_LIB)
if (!CryptAcquireContext(&gCryptProv,
NULL, NULL, PROV_RSA_FULL, 0))

View File

@ -23,6 +23,8 @@
*/
#include <time.h>
#include <stdlib.h>
#include <errno.h>
#include <stdarg.h>
#include "os_port.h"
#ifdef WIN32
@ -66,13 +68,20 @@ EXP_FUNC int STDCALL strcasecmp(const char *s1, const char *s2)
#undef open
#undef fopen
/* some functions that call abort() on failure */
static const char * out_of_mem_str = "out of memory";
static const char * file_open_str = "Could not open file \"%s\"";
/*
* Some functions that call display some error trace and then call abort().
* This just makes life much easier on embedded systems, since we're
* suffering major trauma...
*/
EXP_FUNC void * STDCALL ax_malloc(size_t s)
{
void *x;
if ((x = malloc(s)) == NULL)
abort();
exit_now(out_of_mem_str);
return x;
}
@ -82,7 +91,7 @@ EXP_FUNC void * STDCALL ax_realloc(void *y, size_t s)
void *x;
if ((x = realloc(y, s)) == NULL)
abort();
exit_now(out_of_mem_str);
return x;
}
@ -92,17 +101,20 @@ EXP_FUNC void * STDCALL ax_calloc(size_t n, size_t s)
void *x;
if ((x = calloc(n, s)) == NULL)
abort();
exit_now(out_of_mem_str);
return x;
}
EXP_FUNC FILE * STDCALL ax_fopen(const char *name, const char *type)
EXP_FUNC FILE * STDCALL ax_fopen(const char *pathname, const char *type)
{
FILE *f;
if ((f = fopen(name, type)) == NULL)
abort();
if ((f = fopen(pathname, type)) == NULL)
{
perror("open: ");
exit_now(file_open_str, pathname);
}
return f;
}
@ -112,8 +124,25 @@ EXP_FUNC int STDCALL ax_open(const char *pathname, int flags)
int x;
if ((x = open(pathname, flags)) < 0)
abort();
{
perror("open: ");
exit_now(file_open_str, pathname);
}
return x;
}
/**
* This is a call which will deliberately exit an application, but will
* display some information before dying.
*/
void exit_now(const char *format, ...)
{
va_list argp;
va_start(argp, format);
vsprintf(stderr, format, argp);
va_end(argp);
abort();
}

View File

@ -74,7 +74,7 @@ extern "C" {
#define random() rand()
#define getpid() _getpid()
#define snprintf _snprintf
//#define open(A,B) _open(A,B)
#define open(A,B) _open(A,B)
#define dup2(A,B) _dup2(A,B)
#define unlink(A) _unlink(A)
#define close(A) _close(A)
@ -146,14 +146,18 @@ EXP_FUNC int STDCALL strcasecmp(const char *s1, const char *s2);
#define malloc(A) ax_malloc(A)
#define realloc(A,B) ax_realloc(A,B)
#define calloc(A,B) ax_calloc(A,B)
#define fopen(A,B) ax_fopen(A,B)
#define open(A,B) ax_open(A,B)
EXP_FUNC void * STDCALL ax_malloc(size_t s);
EXP_FUNC void * STDCALL ax_realloc(void *y, size_t s);
EXP_FUNC void * STDCALL ax_calloc(size_t n, size_t s);
EXP_FUNC FILE * STDCALL fopen(const char *name, const char *type);
EXP_FUNC int STDCALL open(const char *pathname, int flags);
EXP_FUNC FILE * STDCALL ax_fopen(const char *name, const char *type);
EXP_FUNC int STDCALL ax_open(const char *pathname, int flags);
#ifdef CONFIG_PLATFORM_LINUX
void exit_now(const char *format, ...) __attribute((noreturn));
#else
void exit_now(const char *format, ...);
#endif
#ifdef __cplusplus
}

View File

@ -996,27 +996,6 @@ int SSL_server_tests(void)
printf("SSL server test \"%s\" passed\n", "Bad After Cert");
TTY_FLUSH();
/* this test should fail */
if ((ret = SSL_server_test(NULL, "Bogus cert", "-cipher RC4-SHA",
"../ssl/test/axTLS.x509_crud.cer", NULL,
"../ssl/test/axTLS.key_512", NULL,
NULL, DEFAULT_SVR_OPTION)) != SSL_ERROR_INVALID_KEY)
goto cleanup;
printf("SSL server test \"%s\" passed\n", "Bogus cert");
TTY_FLUSH();
/* this test should fail */
if ((ret = SSL_server_test(NULL, "Bogus private key",
"-cipher RC4-SHA",
"../ssl/test/axTLS.x509_device.cer", NULL,
"../ssl/test/axTLS.crud", NULL,
NULL, DEFAULT_SVR_OPTION)) != SSL_ERROR_INVALID_KEY)
goto cleanup;
printf("SSL server test \"%s\" passed\n", "Bogus private key");
TTY_FLUSH();
/*
* Key in PEM format
*/
@ -1734,7 +1713,7 @@ int main(int argc, char *argv[])
signal(SIGPIPE, SIG_IGN); /* ignore pipe errors */
dup2(fd, 2);
#endif
bi_ctx = bi_initialize();
if (AES_test(bi_ctx))