mirror of https://github.com/wolfSSL/wolfssh.git
Memory Update
1. Removed the memory API. 2. Wired the existing memory calls back into the wolfCrypt memory calls. 3. Updated the include.am and vcxproj files for the deleted source. The wolfSSH memory API is a shallow copy of the wolfCrypt memory API. wolfCrypt's API offers more options including logging and static memory that may be useful for wolfSSH in the future. Since both APIs were available, wolfSSH's was removed as redundant.pull/150/head
parent
b7c4630b01
commit
883b29d031
|
|
@ -39,7 +39,6 @@
|
|||
<ClCompile Include="..\..\..\src\io.c" />
|
||||
<ClCompile Include="..\..\..\src\keygen.c" />
|
||||
<ClCompile Include="..\..\..\src\log.c" />
|
||||
<ClCompile Include="..\..\..\src\memory.c" />
|
||||
<ClCompile Include="..\..\..\src\port.c" />
|
||||
<ClCompile Include="..\..\..\src\ssh.c" />
|
||||
<ClCompile Include="..\..\..\src\wolfsftp.c" />
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
lib_LTLIBRARIES += src/libwolfssh.la
|
||||
src_libwolfssh_la_SOURCES = src/ssh.c \
|
||||
src/internal.c \
|
||||
src/memory.c \
|
||||
src/log.c \
|
||||
src/io.c \
|
||||
src/port.c
|
||||
|
|
|
|||
109
src/memory.c
109
src/memory.c
|
|
@ -1,109 +0,0 @@
|
|||
/* memory.c
|
||||
*
|
||||
* Copyright (C) 2014-2016 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSH.
|
||||
*
|
||||
* wolfSSH is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wolfSSH is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with wolfSSH. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* The memory module contains the interface to the custom memory handling hooks.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <wolfssh/settings.h>
|
||||
|
||||
|
||||
#ifdef USE_WOLFSSH_MEMORY
|
||||
|
||||
#include <wolfssh/memory.h>
|
||||
#include <wolfssh/error.h>
|
||||
|
||||
/* Set these to default values initially. */
|
||||
static wolfSSH_Malloc_cb malloc_function = NULL;
|
||||
static wolfSSH_Free_cb free_function = NULL;
|
||||
static wolfSSH_Realloc_cb realloc_function = NULL;
|
||||
|
||||
|
||||
/* set wolfSSH allocator callbacks, 0 on success */
|
||||
int wolfSSH_SetAllocators(wolfSSH_Malloc_cb mf,
|
||||
wolfSSH_Free_cb ff,
|
||||
wolfSSH_Realloc_cb rf)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
if (mf)
|
||||
malloc_function = mf;
|
||||
else
|
||||
res = WS_BAD_ARGUMENT;
|
||||
|
||||
if (ff)
|
||||
free_function = ff;
|
||||
else
|
||||
res = WS_BAD_ARGUMENT;
|
||||
|
||||
if (rf)
|
||||
realloc_function = rf;
|
||||
else
|
||||
res = WS_BAD_ARGUMENT;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/* our malloc handler */
|
||||
void* wolfSSH_Malloc(size_t size)
|
||||
{
|
||||
void* res = 0;
|
||||
|
||||
if (malloc_function)
|
||||
res = malloc_function(size);
|
||||
else
|
||||
res = malloc(size);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/* our free handler */
|
||||
void wolfSSH_Free(void *ptr)
|
||||
{
|
||||
if (free_function)
|
||||
free_function(ptr);
|
||||
else
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
|
||||
/* our realloc handler */
|
||||
void* wolfSSH_Realloc(void *ptr, size_t size)
|
||||
{
|
||||
void* res = 0;
|
||||
|
||||
if (realloc_function)
|
||||
res = realloc_function(ptr, size);
|
||||
else
|
||||
res = realloc(ptr, size);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#endif /* USE_WOLFSSH_MEMORY */
|
||||
|
||||
|
|
@ -8,7 +8,6 @@ nobase_include_HEADERS+= \
|
|||
wolfssh/ssh.h \
|
||||
wolfssh/keygen.h \
|
||||
wolfssh/port.h \
|
||||
wolfssh/memory.h \
|
||||
wolfssh/settings.h \
|
||||
wolfssh/error.h \
|
||||
wolfssh/visibility.h \
|
||||
|
|
|
|||
|
|
@ -1,56 +0,0 @@
|
|||
/* memory.h
|
||||
*
|
||||
* Copyright (C) 2014-2016 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSH.
|
||||
*
|
||||
* wolfSSH is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wolfSSH is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with wolfSSH. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* The memory module contains the interface to the custom memory handling hooks.
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <wolfssh/settings.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
typedef void *(*wolfSSH_Malloc_cb)(size_t size);
|
||||
typedef void (*wolfSSH_Free_cb)(void *ptr);
|
||||
typedef void *(*wolfSSH_Realloc_cb)(void *ptr, size_t size);
|
||||
|
||||
|
||||
/* Public set function */
|
||||
WOLFSSH_API int wolfSSH_SetAllocators(wolfSSH_Malloc_cb malloc_function,
|
||||
wolfSSH_Free_cb free_function,
|
||||
wolfSSH_Realloc_cb realloc_function);
|
||||
|
||||
/* Public in case user app wants to use WMALLOC/WFREE */
|
||||
WOLFSSH_API void* wolfSSH_Malloc(size_t size);
|
||||
WOLFSSH_API void wolfSSH_Free(void *ptr);
|
||||
WOLFSSH_API void* wolfSSH_Realloc(void *ptr, size_t size);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -41,11 +41,10 @@ extern "C" {
|
|||
|
||||
/* setup memory handling */
|
||||
#ifndef WMALLOC_USER
|
||||
#include <wolfssh/memory.h>
|
||||
|
||||
#define WMALLOC(s, h, t) ((void)h, (void)t, wolfSSH_Malloc((s)))
|
||||
#define WFREE(p, h, t) {void* xp = (p); if ((xp)) wolfSSH_Free((xp));}
|
||||
#define WREALLOC(p, n, h, t) wolfSSH_Realloc((p), (n))
|
||||
#define WMALLOC(s, h, t) XMALLOC(s, h, t)
|
||||
#define WFREE(p, h, t) XFREE(p, h, t)
|
||||
#define WREALLOC(p, n, h, t) XREALLOC(p, n, h, t)
|
||||
#define wolfSSH_SetAllocators wolfSSL_SetAllocators
|
||||
#endif /* WMALLOC_USER */
|
||||
|
||||
#ifndef WFGETS
|
||||
|
|
|
|||
Loading…
Reference in New Issue