This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit 95abb3628c50839a466bc017112d689e51b9a6ca Author: dongjiuzhu1 <[email protected]> AuthorDate: Wed Feb 21 20:08:37 2024 +0800 system/fastboot: fix crash when free invalid pointer Signed-off-by: dongjiuzhu1 <[email protected]> --- system/fastboot/fastboot.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/system/fastboot/fastboot.c b/system/fastboot/fastboot.c index 80e8aa8a7..a74ba5b36 100644 --- a/system/fastboot/fastboot.c +++ b/system/fastboot/fastboot.c @@ -616,14 +616,17 @@ static void fastboot_publish(FAR struct fastboot_ctx_s *context, FAR struct fastboot_var_s *var; var = malloc(sizeof(*var)); - if (var) + if (var == NULL) { - var->name = name; - var->string = string; - var->data = data; - var->next = context->varlist; - context->varlist = var; + printf("ERROR: Could not allocate the memory.\n"); + return; } + + var->name = name; + var->string = string; + var->data = data; + var->next = context->varlist; + context->varlist = var; } static void fastboot_create_publish(FAR struct fastboot_ctx_s *context) @@ -654,7 +657,7 @@ static void fastboot_free_publish(FAR struct fastboot_ctx_s *context) int main(int argc, FAR char **argv) { - FAR struct fastboot_ctx_s context; + struct fastboot_ctx_s context; FAR void *buffer = NULL; char usbdev[32]; int ret = OK; @@ -722,7 +725,8 @@ int main(int argc, FAR char **argv) goto err_with_in; } - context.flash_fd = -1; + context.varlist = NULL; + context.flash_fd = -1; context.download_buffer = buffer; context.download_size = 0; context.download_offset = 0;
