Message ID | 20200207161820.20186-1-ceggers@arri.de |
---|---|
State | Accepted |
Headers | show |
Series | util: Fix memory leak | expand |
On 07/02/20 17:18, Christian Eggers wrote: > Strings b1 and b2 were not freed if length check fails. > > Signed-off-by: Christian Eggers <ceggers@arri.de> > --- > core/util.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/core/util.c b/core/util.c > index 3c6cde5..3c7db79 100644 > --- a/core/util.c > +++ b/core/util.c > @@ -270,16 +270,20 @@ int get_hw_revision(struct hw_type *hw) > if ((strlen(b1) > (SWUPDATE_GENERAL_STRING_SIZE) - 1) || > (strlen(b2) > (SWUPDATE_GENERAL_STRING_SIZE - 1))) { > ERROR("Board name or revision too long"); > - return -1; > + ret = -1; > + goto out; > } > Good catch, thanks ! > strncpy(hw->boardname, b1, sizeof(hw->boardname)); > strncpy(hw->revision, b2, sizeof(hw->revision)); > > + ret = 0; > + > +out: > free(b1); > free(b2); > > - return 0; > + return ret; > } > > /** > Acked-by: Stefano Babic <sbabic@denx.de> Best regards, Stefano Babic
diff --git a/core/util.c b/core/util.c index 3c6cde5..3c7db79 100644 --- a/core/util.c +++ b/core/util.c @@ -270,16 +270,20 @@ int get_hw_revision(struct hw_type *hw) if ((strlen(b1) > (SWUPDATE_GENERAL_STRING_SIZE) - 1) || (strlen(b2) > (SWUPDATE_GENERAL_STRING_SIZE - 1))) { ERROR("Board name or revision too long"); - return -1; + ret = -1; + goto out; } strncpy(hw->boardname, b1, sizeof(hw->boardname)); strncpy(hw->revision, b2, sizeof(hw->revision)); + ret = 0; + +out: free(b1); free(b2); - return 0; + return ret; } /**
Strings b1 and b2 were not freed if length check fails. Signed-off-by: Christian Eggers <ceggers@arri.de> --- core/util.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)