Skip to content
Permalink
Browse files

netrc: free 'home' on error

Follow-up to f9c7ba9

Coverity CID 1453474

Closes #4291
  • Loading branch information...
bagder committed Sep 3, 2019
1 parent 4ac2884 commit 158dcb9f86986bebdb39ecd44237f112c72d761c
Showing with 12 additions and 7 deletions.
  1. +12 −7 lib/netrc.c
@@ -218,18 +218,18 @@ int Curl_parsenetrc(const char *host,
char *filealloc = NULL;

if(!netrcfile) {
char *home = curl_getenv("HOME"); /* portable environment reader */
if(home) {
char *home = NULL;
char *homea = curl_getenv("HOME"); /* portable environment reader */
if(homea) {
home = homea;
#if defined(HAVE_GETPWUID_R) && defined(HAVE_GETEUID)
}
else {
struct passwd pw, *pw_res;
char pwbuf[1024];
if(!getpwuid_r(geteuid(), &pw, pwbuf, sizeof(pwbuf), &pw_res)
&& pw_res) {
home = strdup(pw.pw_dir);
if(!home)
return -1;
home = pw.pw_dir;
}
#elif defined(HAVE_GETPWUID) && defined(HAVE_GETEUID)
}
@@ -247,22 +247,27 @@ int Curl_parsenetrc(const char *host,
memory) */

filealloc = curl_maprintf("%s%s.netrc", home, DIR_CHAR);
if(!filealloc)
if(!filealloc) {
free(homea);
return -1;
}
retcode = parsenetrc(host, loginp, passwordp, login_changed,
password_changed, filealloc);
free(filealloc);
#ifdef WIN32
if(retcode == NETRC_FILE_MISSING) {
/* fallback to the old-style "_netrc" file */
filealloc = curl_maprintf("%s%s_netrc", home, DIR_CHAR);
if(!filealloc)
if(!filealloc) {
free(homea);
return -1;
}
retcode = parsenetrc(host, loginp, passwordp, login_changed,
password_changed, filealloc);
free(filealloc);
}
#endif
free(homea);
}
else
retcode = parsenetrc(host, loginp, passwordp, login_changed,

0 comments on commit 158dcb9

Please sign in to comment.
You can’t perform that action at this time.