Skip to content

Commit

Permalink
example/libtest: add malloc/free to libtest
Browse files Browse the repository at this point in the history
So we can verify flags like kasan are effective or not.

Signed-off-by: xuxingliang <[email protected]>
  • Loading branch information
XuNeo committed Oct 27, 2024
1 parent 1506c6f commit 102eb17
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 13 additions & 1 deletion examples/libtest/libtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
* Included Files
****************************************************************************/

#include <nuttx/config.h>
#include <nuttx/compiler.h>
#include <stdio.h>
#include <stdlib.h>

/****************************************************************************
* Public Functions
Expand All @@ -35,5 +36,16 @@

void library_test(void)
{
FAR int *p = malloc(sizeof(int));
if (p == NULL)
{
printf("libtest failed to allocate memory\n");
return;
}

*p = 12345;
printf("libtest: p=%p *p=%d\n", p, *p);
free(p);

printf("Hello, Library!!\n");
}
3 changes: 1 addition & 2 deletions examples/libtest/libtest_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
* Included Files
****************************************************************************/

#include <nuttx/config.h>
#include <stdio.h>
#include <nuttx/compiler.h>
#include "libtest.h"

/****************************************************************************
Expand Down

0 comments on commit 102eb17

Please sign in to comment.