File tree Expand file tree Collapse file tree 1 file changed +3
-16
lines changed
Expand file tree Collapse file tree 1 file changed +3
-16
lines changed Original file line number Diff line number Diff line change 2727#include <stdint.h>
2828#include <stddef.h> /* For NULL */
2929
30- #if defined(WOLFHSM_CFG_FLASH_RAMSIM_MALLOC )
31- #include <stdlib.h> /* For malloc/free */
32- #endif
33-
3430#include <string.h>
3531#include <stdbool.h>
3632
@@ -63,21 +59,19 @@ int whFlashRamsim_Init(void* context, const void* config)
6359 const whFlashRamsimCfg * cfg = (const whFlashRamsimCfg * )config ;
6460
6561 if (ctx == NULL || cfg == NULL || (cfg -> sectorSize == 0 ) ||
66- (cfg -> pageSize == 0 ) || (cfg -> sectorSize % cfg -> pageSize != 0 )) {
62+ (cfg -> pageSize == 0 ) || (cfg -> sectorSize % cfg -> pageSize != 0 ) ||
63+ cfg -> memory == NULL || cfg -> size == 0 ) {
6764 return WH_ERROR_BADARGS ;
6865 }
6966
67+ memset (ctx , 0 , sizeof (* ctx );
7068 ctx -> size = cfg -> size ;
7169 ctx -> sectorSize = cfg -> sectorSize ;
7270 ctx -> pageSize = cfg -> pageSize ;
7371 ctx -> memory = cfg -> memory ;
7472 ctx -> erasedByte = cfg -> erasedByte ;
7573 ctx -> writeLocked = 0 ;
7674
77- if (!ctx -> memory ) {
78- return WH_ERROR_BADARGS ;
79- }
80-
8175 /* Initialize memory based on initData or simulate starting from erased flash */
8276 if (cfg -> initData != NULL ) {
8377 memcpy (ctx -> memory , cfg -> initData , ctx -> size );
@@ -96,13 +90,6 @@ int whFlashRamsim_Cleanup(void* context)
9690 return WH_ERROR_BADARGS ;
9791 }
9892
99- #if defined(WOLFHSM_CFG_FLASH_RAMSIM_MALLOC )
100- if (ctx -> memory != NULL ) {
101- free (ctx -> memory );
102- ctx -> memory = NULL ;
103- }
104- #endif
105-
10693 return WH_ERROR_OK ;
10794}
10895
You can’t perform that action at this time.
0 commit comments