NIMU Device object contains memory leak if NIMURegister() fails

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: Medium
    • TI Device Drivers
    • TIDRIVERS-3834
    • 3.01.00
    • TIDRIVERS_5_30_00
    • MSP432E4
    • Potential memory leak in NIMU Device object if NIMURegister() failed has been fixed.

      Need to free the NIMU device object if NIMURegister() fails.

      In the NIMUInit() fxn, the NIMU device object is allocated using mmAlloc():

          /* Allocate memory for the EMAC. Memory freed in the NDK stack shutdown */                                                                                                 
          device = mmAlloc(sizeof(NETIF_DEVICE));                                                                                                                                    
          if (device == NULL) {                                                                                                                                                      
              return (-1);                                                                                                                                                           
          }        
      

      Note first that if all goes well and NIMUInit() successfully returns, the allocated object will be freed later within the stack code in NIMU_UnRegister().

      Otherwise, this object should be freed within the NIMUInit() function at various points of failure, and is, but there's one place that was overlooked before. In the below code, there should be a call to mmFree() prior to returning:

          /* Register the device with NIMU */                                                                                                                                        
          if (NIMURegister(device) < 0) {                                                                                                                                            
              return (-1);                                                                                                                                                           
          }        
      

      If NIMURegister() fails, then NIMU_UnRegister() is never called, and so no one will ever free the device.

            Assignee:
            TI User
            Reporter:
            TI User
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Connection: Intermediate to External PROD System
                EXTSYNC-2530 - NIMU Device object contains memory ...
                SYNCHRONIZED
                • Last Sync Date: