xtest: remove HEAP_ALLOC and friends
Replaces calls HEAP_ALLOC(), HEAP_FREE() and SecUtil_Heap_StrDup() with
calls to calloc(), free() and strdup() respectively.
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
diff --git a/host/xtest/adbg/src/adbg_case.c b/host/xtest/adbg/src/adbg_case.c
index 4e3ccb1..9515d58 100644
--- a/host/xtest/adbg/src/adbg_case.c
+++ b/host/xtest/adbg/src/adbg_case.c
@@ -49,21 +49,17 @@
{
ADBG_Case_t *Case_p;
- Case_p = HEAP_ALLOC(ADBG_Case_t);
- if (Case_p == NULL)
- return NULL;
+ Case_p = calloc(1, sizeof(*Case_p));
+ if (Case_p)
+ Case_p->SuiteEntry_p = SuiteEntry_p;
- memset(Case_p, 0, sizeof(ADBG_Case_t));
- Case_p->SuiteEntry_p = SuiteEntry_p;
return Case_p;
}
-void ADBG_Case_Delete(
- ADBG_Case_t *Case_p
- )
+void ADBG_Case_Delete(ADBG_Case_t *Case_p)
{
ADBG_SubCase_Delete(Case_p->FirstSubCase_p);
- HEAP_FREE(&Case_p);
+ free(Case_p);
}
bool ADBG_Case_SubCaseIsMain(
@@ -283,14 +279,13 @@
{
ADBG_SubCase_t *SubCase_p;
- SubCase_p = HEAP_ALLOC(ADBG_SubCase_t);
+ SubCase_p = calloc(1, sizeof(*SubCase_p));
if (SubCase_p == NULL)
goto ErrorReturn;
- memset(SubCase_p, 0, sizeof(ADBG_SubCase_t));
TAILQ_INIT(&SubCase_p->SubCasesList);
- SubCase_p->Title_p = SECUTIL_HEAP_STRDUP(Title_p);
+ SubCase_p->Title_p = strdup(Title_p);
if (SubCase_p->Title_p == NULL)
goto ErrorReturn;
@@ -299,8 +294,7 @@
if (SubCase_p->Parent_p == NULL) {
/* Main SubCase */
- SubCase_p->TestID_p =
- SECUTIL_HEAP_STRDUP(ADBG_Case_GetTestID(Case_p));
+ SubCase_p->TestID_p = strdup(ADBG_Case_GetTestID(Case_p));
if (SubCase_p->TestID_p == NULL)
goto ErrorReturn;
@@ -313,7 +307,7 @@
Parent_p->Result.NumSubCases++;
snprintf(PrefixTitle, sizeof(PrefixTitle), "%s.%d",
Parent_p->TestID_p, Parent_p->Result.NumSubCases);
- SubCase_p->TestID_p = SECUTIL_HEAP_STRDUP(PrefixTitle);
+ SubCase_p->TestID_p = strdup(PrefixTitle);
if (SubCase_p->TestID_p == NULL)
goto ErrorReturn;
@@ -348,9 +342,9 @@
TAILQ_REMOVE(&SubCase_p->SubCasesList, s, Link);
ADBG_SubCase_Delete(s);
}
- HEAP_FREE(&SubCase_p->TestID_p);
- HEAP_FREE(&SubCase_p->Title_p);
- HEAP_FREE(&SubCase_p);
+ free(SubCase_p->TestID_p);
+ free(SubCase_p->Title_p);
+ free(SubCase_p);
}
}
diff --git a/host/xtest/adbg/src/adbg_int.h b/host/xtest/adbg/src/adbg_int.h
index 5465262..8c87b2a 100644
--- a/host/xtest/adbg/src/adbg_int.h
+++ b/host/xtest/adbg/src/adbg_int.h
@@ -95,11 +95,6 @@
bool ADBG_TestIDMatches(const char *const TestID_p,
const char *const Argument_p);
-#define HEAP_ALLOC(x) ((x *)malloc(sizeof(x)))
-#define HEAP_UNTYPED_ALLOC(x) malloc((x))
-#define HEAP_FREE(x) do { if (*(x) != NULL) { free(*(x)); *(x) = NULL; \
- } } while (0)
-
#define IDENTIFIER_NOT_USED(x) { if (sizeof(&x)) {} }
#endif /* ADBG_INT_H */
diff --git a/host/xtest/adbg/src/adbg_run.c b/host/xtest/adbg/src/adbg_run.c
index bbda656..66509c4 100644
--- a/host/xtest/adbg/src/adbg_run.c
+++ b/host/xtest/adbg/src/adbg_run.c
@@ -52,18 +52,17 @@
{
ADBG_Runner_t *Runner_p;
- Runner_p = HEAP_ALLOC(ADBG_Runner_t);
+ Runner_p = calloc(1, sizeof(*Runner_p));
if (Runner_p == NULL) {
- Do_ADBG_Log("HEAP_ALLOC failed for Suite %s!",
+ Do_ADBG_Log("calloc failed for Suite %s!",
Suite_p->SuiteID_p);
return -1;
}
- memset(Runner_p, 0, sizeof(ADBG_Runner_t));
TAILQ_INIT(&Runner_p->CasesList);
Runner_p->Suite_p = Suite_p;
int ret = ADBG_RunSuite(Runner_p, argc, argv);
- HEAP_FREE(&Runner_p);
+ free(Runner_p);
return ret;
}
diff --git a/host/xtest/adbg/src/security_utils_mem.c b/host/xtest/adbg/src/security_utils_mem.c
index f5b9acb..07d9984 100644
--- a/host/xtest/adbg/src/security_utils_mem.c
+++ b/host/xtest/adbg/src/security_utils_mem.c
@@ -37,19 +37,6 @@
/*************************************************************************
* 5. Definition of external functions
*************************************************************************/
-char *SecUtil_Heap_StrDup(
- const char *const String_p,
- const bool Unsafe,
- const char *const File_p,
- const unsigned int Line
- )
-{
- (void)&Unsafe;
- (void)&File_p;
- (void)&Line;
- return strdup(String_p);
-}
-
void SecUtil_WipeMemory(
void *const Buffer_p,
const size_t BufferLength