Compare commits

...

9 Commits

Author SHA1 Message Date
8ddf982e78 Merge branch 'finley' 2024-04-14 22:50:57 +02:00
9c30ea4ef1 Merge branch 'master' 2024-04-14 22:50:18 +02:00
62f45f7256 fix memory leaks 2024-04-14 22:47:18 +02:00
Dennis Boekholtz
92eb70f4b5 Merge branch 'Dennis_CCS' 2024-04-14 21:10:48 +02:00
Dennis Boekholtz
cb7b573eed Merge branch 'master' into Dennis_CCS 2024-04-14 21:10:15 +02:00
Dennis Boekholtz
04eebfc3fc CLI & History features aan gezet en werkende gekregen op CC3220 2024-04-14 21:09:20 +02:00
Dennis Boekholtz
51c1c28756 Merge branch 'Dennis_CCS' 2024-04-14 15:00:33 +02:00
Dennis Boekholtz
cd72e519a1 Merge branch 'master' into Dennis_CCS 2024-04-14 14:57:10 +02:00
df2129a1bb history: fix memory leak 2024-04-14 12:28:27 +02:00
4 changed files with 19 additions and 9 deletions

View File

@ -6,6 +6,7 @@
#include <limits.h>
// #include <config.h>
#define HISTORY
#include "../FIFOBuff/FIFOBuffChar.h"
#ifdef HISTORY
@ -68,7 +69,7 @@ bool CLI_deinit()
FIFOBuffChar_delete(FIFO);
#ifdef HISTORY
History_deinit(History);
History_deinit(History, true);
#endif
return true;
}
@ -95,9 +96,10 @@ void CLI_PrintHistory()
{
char** historyList;
int ret = History_getFullHistory(History, &historyList);
int i;
if (ret >= 0)
{
for (int i=0; *(historyList + i) != NULL; i++)
for (i=0; *(historyList + i) != NULL; i++)
{
printf("%03i: %s\n", i, *(historyList + i));
}
@ -262,6 +264,7 @@ bool CLI_charIn(char c)
FIFOBuffChar_delete(fifo);
break;
case 8:
case 127: // backspace
if (FIFOBuffChar_pop(FIFO))
{ // pop something of the buffer

View File

@ -17,7 +17,8 @@ CMDList_t* CMDList_init()
// does not free up the commands
int CMDList_deinit(CMDList_t *list)
{
CMDList_t** list_p = (CMDList_t**)list;
CMDList_t** list_p;
*list_p = list;
int i;
for (i = 0; i < 26; i++)
@ -28,7 +29,7 @@ int CMDList_deinit(CMDList_t *list)
}
}
free(*list_p);
free(list);
return 0;
}
@ -44,7 +45,7 @@ int CMDList_add(CMDList_t *list, CMD_t* cmd, char* cmdName)
read_p = cmd->cmd;
}
while (returnCode == 0)
while (returnCode >= 0)
{
char c = *read_p & (~0x20); // convert to uppercase
if ((c >= 'A') && (c <= 'Z'))

View File

@ -19,7 +19,7 @@ History_t* History_init()
}
int History_deinit(History_t* history)
int History_deinit(History_t* history, bool freeLines)
{
// Check if the buffer there is something in the buffer
if (history->FirstEl_p == NULL)
@ -29,6 +29,10 @@ int History_deinit(History_t* history)
while (el != NULL)
{
History_element_t* nextEl = el->nextEl_p;
if (freeLines)
{
free(el->line);
}
free(el);
el = nextEl;
}
@ -149,7 +153,8 @@ int History_getFullHistory(History_t* history, char*** list)
*list = malloc(sizeof(char**) * (History_getSize(history) + 1));
History_element_t* el = history->FirstEl_p;
for (int i = 0; (i < History_getSize(history)-1) && (retCode >= 0); i++)
int i;
for (i = 0; (i < History_getSize(history)-1) && (retCode >= 0); i++)
{
*((*list) + i) = el->line;
if (el->nextEl_p == NULL)
@ -178,7 +183,8 @@ int History_getCurrPos(History_t* history)
if (history->CurrEl_p != NULL)
{
History_element_t* el = history->FirstEl_p;
for (int i = 0; (el != history->CurrEl_p) && (retCode >= 0); i++)
int i;
for (i = 0; (el != history->CurrEl_p) && (retCode >= 0); i++)
{
if (el->nextEl_p == NULL)
{

View File

@ -22,7 +22,7 @@ typedef struct History_s {
extern History_t* History_init();
// destroy a fifo buffer (free up its space)
extern int History_deinit(History_t* history);
extern int History_deinit(History_t* history, bool freeLines);
// put value i in buffer if there is still memory avaliable
extern int History_put(History_t *history, char* line);