Prevent potential nullptr dereference.

Found by clang static analyzer.
This commit is contained in:
John Ralls 2018-11-28 15:36:06 +09:00
parent faba7975ac
commit 606d9cfee6
3 changed files with 18 additions and 9 deletions

View File

@ -987,10 +987,13 @@ gncCustomerGetCachedBalance (GncCustomer *cust)
void gncCustomerSetCachedBalance (GncCustomer *cust, const gnc_numeric *new_bal)
{
if (!new_bal && cust->balance)
if (!new_bal)
{
g_free (cust->balance);
cust->balance = NULL;
if (cust->balance)
{
g_free (cust->balance);
cust->balance = NULL;
}
return;
}

View File

@ -962,10 +962,13 @@ gncEmployeeGetCachedBalance (GncEmployee *empl)
void gncEmployeeSetCachedBalance (GncEmployee *empl, const gnc_numeric *new_bal)
{
if (!new_bal && empl->balance)
if (!new_bal)
{
g_free (empl->balance);
empl->balance = NULL;
if (empl->balance)
{
g_free (empl->balance);
empl->balance = NULL;
}
return;
}

View File

@ -1040,10 +1040,13 @@ gncVendorGetCachedBalance (GncVendor *vend)
void gncVendorSetCachedBalance (GncVendor *vend, const gnc_numeric *new_bal)
{
if (!new_bal && vend->balance)
if (!new_bal)
{
g_free (vend->balance);
vend->balance = NULL;
if (vend->balance)
{
g_free (vend->balance);
vend->balance = NULL;
}
return;
}