Skip to content

Commit

Permalink
[gnc-quotes] g_free a char* from gnc_prefs_get_string
Browse files Browse the repository at this point in the history
ultimately gets char* from g_settings_get_string and must be freed
  • Loading branch information
christopherlam committed Mar 19, 2023
1 parent f9bb056 commit 97f0653
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libgnucash/app-utils/gnc-quotes.cpp
Expand Up @@ -178,10 +178,16 @@ m_version{}, m_sources{}, m_api_key{}

auto av_key = gnc_prefs_get_string ("general.finance-quote", "alphavantage-api-key");
if (!(av_key && *av_key))
{
g_free (av_key);
av_key = getenv("ALPHAVANTAGE_API_KEY");

This comment has been minimized.

Copy link
@jralls

jralls Mar 19, 2023

Member

getenv returns a pointer to an libc internal buffer. Trying to free it will crash.

This comment has been minimized.

Copy link
@christopherlam

christopherlam Mar 20, 2023

Author Contributor

Oops, good catch

}

if (av_key)
{
m_api_key = std::string(av_key);
g_free (av_key);
}
else
PWARN("No Alpha Vantage API key set, currency quotes and other AlphaVantage based quotes won't work.");
}
Expand Down

0 comments on commit 97f0653

Please sign in to comment.