summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2019-09-03 13:46:36 +0200
committerDaniel Stenberg <daniel@haxx.se>2019-09-03 13:46:36 +0200
commitec49962140e2c64c87b16f7f5984a34f47d90782 (patch)
tree4f95c5a620d68ba3f1849257688458b941d6a72c
parent5050edb12484551f4c666212409c117cf38f9784 (diff)
downloadcurl-bagder/netrc-leak.tar.gz
netrc: free 'home' on errorbagder/netrc-leak
Follow-up to f9c7ba9096ec2 Coverity CID 1453474
-rw-r--r--lib/netrc.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/netrc.c b/lib/netrc.c
index bceca53f2..c74065e81 100644
--- a/lib/netrc.c
+++ b/lib/netrc.c
@@ -218,8 +218,10 @@ 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 {
@@ -227,9 +229,7 @@ int Curl_parsenetrc(const char *host,
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,8 +247,10 @@ 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);
@@ -256,13 +258,16 @@ int Curl_parsenetrc(const char *host,
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,