5 Replies Latest reply on Feb 16, 2020 1:24 AM by AxLi_1746341

    WICED 6.4.0 How to fix LwIP assert freeing a buffer already free ?

    user_4051776

      We are using HTTPS for sending ~1K Byte data blocks from STM32F4 over WIFI. Everything works, but occasionally

      we see this assert in memp.c    in function:  do_memp_free_pool(),    line 435:

       

      #if defined( LWIP_DEBUG ) && (! defined( LWIP_NOASSERT ) )

        {

            /* Check if the buffer is already in the free list */

            struct memp * tmp_memp = *desc->tab;

            while ( tmp_memp != NULL )

            {

                LWIP_ASSERT( Freeing a buffer that is already freed, tmp_memp != memp );

                tmp_memp = tmp_memp->next;

            }

        }

      #endif /* if defined( LWIP_DEBUG ) && (! defined( LWIP_NOASSERT ) ) */

       

      How can we get rid of this assert without interrupting the transfer - our large data file is critical to get to the destination.

      We also noticed that this assert is enabled with:  LWIP_DEBUG enabled and LWIP_NOASSERT disabled !

       

      Would it be safe to simply disable this assert ? Appreciate answers from those who have seen this memory leak issue.

      --

      Thanks, BM

        • 1. Re: WICED 6.4.0 How to fix LwIP assert freeing a buffer already free ?
          MuraliR_36

          Hi

           

          The assert by default gets triggered if you have enabled the debug flag. Is this the case or do you have any other implementation?

          In the default case, if you disable the debug flag, it should be enough to disable the asserts.Also it would be better if you test your application after disabling the flag to ensure that the required behaviour is being observed.

           

          Thanks

          • 2. Re: WICED 6.4.0 How to fix LwIP assert freeing a buffer already free ?
            user_4051776

            MuraliR_36

            Thank you so much. We tried to enable the  LWIP_NOASSERT but the build failed. We have not tried to disable the LWIP_DEBUG.  The reason for this assert is that the server disconnect HTTP first, and later we disconnect ourselves - probably this is how to the assert happened. We'll try to disable it for now.

            --

            Thank you again,

            BM

            • 3. Re: WICED 6.4.0 How to fix LwIP assert freeing a buffer already free ?
              RaktimR_11

              BM,

               

              You can define LWIP_NOASSERT in 43xxx_Wi-Fi/WICED/network/LwIP/WWD/FreeRTOS/arch/cc.h. But after disabling the asserts, using the option mentioned, wwd_network.c compilation is going to fail. Is that the error you are seeing when you say build failed?

               

              If that's the case, migrate to 43xxx_Wi-Fi/WICED/network/LwIP/WWD/wwd_network.c and modify one of the LWIP_ASSERT to wiced_assert. In my case, I changed netif allocation assert from LWIP_ASSERT to wiced_assert (line #286) and compilation went through.

               

              if ( tmp_netif == NULL )
                          {
                              /* Received a packet for a network interface is not initialised Cannot do anything with packet - just drop it. */
                              result = pbuf_free( buffer ); //wiced_assert
                              wiced_assert("Failed to release packet buffer", ( result != (u8_t)0 ) );
                              buffer = NULL;
                              return;
                          }
              

               

              Why is this modification required? LWIP_NOASSERT disables all sort of asserts from LwIP library but the wwd port of LwIP section uses this assert for error checking. Hence, even if all the IP related operations are successful, you can get -Werror=unused-but-set-variable because some of the variables inside wwd_network.c remain unused if no assert is enabled although it stores the return value from API calls which probably is throwing the build error.

               

              Hope this helps!

              2 of 2 people found this helpful
              • 4. Re: WICED 6.4.0 How to fix LwIP assert freeing a buffer already free ?
                user_4051776

                Yes, we saw the compilation failing after defining LWIP_NOASSERT in cc.h

                Thank you for the new recommendations - it seems this is the right way.  -- Thanks, BMM

                 

                • 5. Re: WICED 6.4.0 How to fix LwIP assert freeing a buffer already free ?
                  AxLi_1746341

                  user_4051776 wrote:

                   

                  We are using HTTPS for sending ~1K Byte data blocks from STM32F4 over WIFI. Everything works, but occasionally

                  we see this assert in memp.c    in function:  do_memp_free_pool(),    line 435:

                   

                  #if defined( LWIP_DEBUG ) && (! defined( LWIP_NOASSERT ) )

                    {

                        /* Check if the buffer is already in the free list */

                        struct memp * tmp_memp = *desc->tab;

                        while ( tmp_memp != NULL )

                        {

                            LWIP_ASSERT( Freeing a buffer that is already freed, tmp_memp != memp );

                            tmp_memp = tmp_memp->next;

                        }

                    }

                  #endif /* if defined( LWIP_DEBUG ) && (! defined( LWIP_NOASSERT ) ) */

                   

                  Above assertion is not in upstream lwip code, it's added by WICED.

                  So why WICED add this assertion?