Hi,
I am using CJSON_LIB from nrf-sdk modules, I even tested this cjson lib in such a simple way in helloworld app (I attached the sample project.), and after running for a while, I have a no memory space issue, Any idea? I was expecting to free up the memory by running cJSON_Delete(root_obj); these cjson libs are used in the asset tracker application. So it means this issue is valid for atv2 app as well?, Could you please verify?
{"status":{"echo":"error_report->cmd_echo","cmd":"cmd2str(error_report->cmd)","sub_cmd":"dev_sub_cmd2str(error_report->sub_cmd.dev_sub_cmd)","step":"common_steps2str(error_report->step[error_report->dev_type])","result":"dev_result2str(error_report->result)"},"data":{"ret":"error_report->data.data_str","type":"type2str(error_report->type)"}}
2143
40 main.c
53 main.c
61 main.c
75 main.c
77 main.c
91 main.c
92 main.c
94 main.c
105 main.c
{"status":{"echo":"error_report->cmd_echo","cmd":"cmd2str(error_report->cmd)","sub_cmd":"dev_sub_cmd2str(error_report->sub_cmd.dev_sub_cmd)","step":"common_steps2str(error_report->step[error_report->dev_type])","result":"dev_result2str(error_report->result)"},"data":{"ret":"error_report->data.data_str","type":"type2str(error_report->type)"}}
2144
40 main.c
53 main.c
61 main.c
75 main.c
77 main.c
91 main.c
92 main.c
94 main.c
105 main.c
{"status":{"echo":"error_report->cmd_echo","cmd":"cmd2str(error_report->cmd)","sub_cmd":"dev_sub_cmd2str(error_report->sub_cmd.dev_sub_cmd)","step":"common_steps2str(error_report->step[error_report->dev_type])","result":"dev_result2str(error_report->result)"},"data":{"ret":"error_report->data.data_str","type":"type2str(error_report->type)"}}
2145
40 main.c
53 main.c
61 main.c
75 main.c
77 main.c
91 main.c
92 main.c
94 main.c
105 main.c
{"status":{"echo":"error_report->cmd_echo","cmd":"cmd2str(error_report->cmd)","sub_cmd":"dev_sub_cmd2str(error_report->sub_cmd.dev_sub_cmd)","step":"common_steps2str(error_report->step[error_report->dev_type])","result":"dev_result2str(error_report->result)"},"data":{"ret":"error_report->data.data_str","type":"type2str(error_report->type)"}}
2146
40 main.c
53 main.c
61 main.c
75 main.c
77 main.c
91 main.c
92 main.c
94 main.c
105 main.c
{"status":{"echo":"error_report->cmd_echo","cmd":"cmd2str(error_report->cmd)","sub_cmd":"dev_sub_cmd2str(error_report->sub_cmd.dev_sub_cmd)","step":"common_steps2str(error_report->step[error_report->dev_type])","result":"dev_result2str(error_report->result)"},"data":{"ret":"error_report->data.data_str","type":"type2str(error_report->type)"}}
2147
40 main.c
53 main.c
61 main.c
75 main.c
77 main.c
91 main.c
92 main.c
94 main.c
97 main.c
105 main.c
[00:03:45.874,000] <err> os: ***** BUS FAULT *****
[00:03:45.874,000] <err> os: Precise data bus error
[00:03:45.874,000] <err> os: BFAR Address: 0x0
[00:03:45.874,000] <err> os: r0/a1: 0x00000000 r1/a2: 0x0800bf3a r2/a3: 0x00000000
[00:03:45.874,000] <err> os: r3/a4: 0x00000000 r12/ip: 0x00007252 r14/lr: 0x08001f35
[00:03:45.874,000] <err> os: xpsr: 0x61000000
[00:03:45.874,000] <err> os: Faulting instruction address (r15/pc): 0x08000e32
[00:03:45.874,000] <err> os: >>> ZEPHYR FATAL ERROR 25: Unknown error on CPU 0
[00:03:45.874,000] <err> os: Current thread: 0x20002e20 (unknown)
[00:03:46.016,000] <err> fatal_error: Resetting system*** Booting nRF Connect SDK v3.6.0 ***
in the test app: I am printing encoded json data with a 100ms delay (just to see error quickly), after printing 2147 times, memory issue happpend
here is the code:
#define FILE_NAME "main.c"
struct usb_codec_data {
/** Encoded output. */
char *buf;
/** Length of encoded output. */
size_t len;
};
static void encode_json(struct usb_codec_data * usb_log)
{
int err = 0;
__ASSERT_NO_MSG(error_report != NULL);
cJSON *root_obj = cJSON_CreateObject();
cJSON *sub_obj = cJSON_CreateObject();
cJSON *data_obj = cJSON_CreateObject();
if (root_obj == NULL || sub_obj == NULL|| data_obj == NULL) {
printk("%d %s\n", __LINE__, FILE_NAME);
err = -ENOMEM;
goto exit;
}
printk("%d %s\n", __LINE__, FILE_NAME);
err = json_add_str(sub_obj, CMD_ECHO, "error_report->cmd_echo");
if (err)
{
printk("Encoding error: %d returned at %s:%d\n", err, __FILE__, __LINE__);
goto exit;
}
err = json_add_str(sub_obj, CMD_FOR, "cmd2str(error_report->cmd)");
if (err)
{
printk("Encoding error: %d returned at %s:%d\n", err, __FILE__, __LINE__);
goto exit;
}
printk("%d %s\n", __LINE__, FILE_NAME);
err = json_add_str(sub_obj, CMD_SUB_FOR, "dev_sub_cmd2str(error_report->sub_cmd.dev_sub_cmd)");
if (err)
{
printk("Encoding error: %d returned at %s:%d\n", err, __FILE__, __LINE__);
goto exit;
}
printk("%d %s\n", __LINE__, FILE_NAME);
err = json_add_str(sub_obj, CMD_STEP, "common_steps2str(error_report->step[error_report->dev_type])");
if (err)
{
printk("Encoding error: %d returned at %s:%d\n", err, __FILE__, __LINE__);
goto exit;
}
err = json_add_str(sub_obj, CMD_RESULT, "dev_result2str(error_report->result)");
if (err)
{
printk("Encoding error: %d returned at %s:%d\n", err, __FILE__, __LINE__);
goto exit;
}
printk("%d %s\n", __LINE__, FILE_NAME);
json_add_obj(root_obj, OBJECT_STATUS, sub_obj);
printk("%d %s\n", __LINE__, FILE_NAME);
err = json_add_str(data_obj, CMD_RETURN_OBJ, "error_report->data.data_str");
if (err)
{
printk("Encoding error: %d returned at %s:%d\n", err, __FILE__, __LINE__);
goto exit;
}
err = json_add_str(data_obj, CMD_RETURN_TYPE, "type2str(error_report->type)");
if (err)
{
printk("Encoding error: %d returned at %s:%d\n", err, __FILE__, __LINE__);
goto exit;
}
printk("%d %s\n", __LINE__, FILE_NAME);
printk("%d %s\n", __LINE__, FILE_NAME);
json_add_obj(root_obj, OBJECT_DATA, data_obj);
printk("%d %s\n", __LINE__, FILE_NAME);
char *buffer = cJSON_PrintUnformatted(root_obj);
if (buffer == NULL) {
printk("%d %s\n", __LINE__, FILE_NAME);
err = -ENOMEM;
goto exit;
}
usb_log->buf = buffer;
usb_log->len = strlen(buffer);
exit:
cJSON_Delete(root_obj);
printk("%d %s\n", __LINE__, FILE_NAME);
return;
}
int main(void)
{
int i = 0;
k_msleep(10000);
while(1)
{
struct usb_codec_data usb_log = {0};
encode_json(&usb_log);
printk("%s\n",usb_log.buf);
printk("%d\n", i++);
k_msleep(100);
encode_json(&usb_log);
printk("%s\n",usb_log.buf);
printk("%d\n", i++);
k_msleep(100);
// printf("Hello World! %s\n", CONFIG_BOARD);
// encode_json_log();
}
}