This is an automated email from the ASF dual-hosted git repository.

vipulrahane pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new e0ffa24  battery: calloc failure should be accounted for
     new 9c28a35  Merge pull request #2288 from 
vrahane/cid_10078_resource_leak_battery
e0ffa24 is described below

commit e0ffa2493c753a68ea30475a2a3945beaf41e0ca
Author: Vipul Rahane <[email protected]>
AuthorDate: Tue May 12 12:06:57 2020 -0700

    battery: calloc failure should be accounted for
---
 hw/battery/src/battery.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/hw/battery/src/battery.c b/hw/battery/src/battery.c
index 98a45cf..b622966 100644
--- a/hw/battery/src/battery.c
+++ b/hw/battery/src/battery.c
@@ -297,6 +297,10 @@ battery_find_property(struct os_dev *battery,
             if (prop) {
                 struct battery_property *p =
                     calloc(1, sizeof(struct battery_property));
+                if (!p) {
+                    /* If an allocation fails, return NULL */
+                    return NULL;
+                }
                 if (prop->bp_prop_num == 0) {
                     prop->bp_prop_num = ++bat->b_all_property_count;
                     assert(bat->b_all_property_count <= 
BATTERY_MAX_PROPERTY_COUNT);
@@ -314,6 +318,7 @@ battery_find_property(struct os_dev *battery,
             }
         }
     }
+
     return res;
 }
 

Reply via email to