Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
bc42479a
Commit
bc42479a
authored
Oct 13, 2014
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup memory leak in ssh transport
parent
cdd71711
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
34 deletions
+28
-34
src/transports/ssh.c
+28
-34
No files found.
src/transports/ssh.c
View file @
bc42479a
...
@@ -457,27 +457,31 @@ static int _git_ssh_setup_conn(
...
@@ -457,27 +457,31 @@ static int _git_ssh_setup_conn(
LIBSSH2_SESSION
*
session
=
NULL
;
LIBSSH2_SESSION
*
session
=
NULL
;
LIBSSH2_CHANNEL
*
channel
=
NULL
;
LIBSSH2_CHANNEL
*
channel
=
NULL
;
t
->
current_stream
=
NULL
;
*
stream
=
NULL
;
*
stream
=
NULL
;
if
(
ssh_stream_alloc
(
t
,
url
,
cmd
,
stream
)
<
0
)
if
(
ssh_stream_alloc
(
t
,
url
,
cmd
,
stream
)
<
0
)
return
-
1
;
return
-
1
;
s
=
(
ssh_stream
*
)
*
stream
;
s
=
(
ssh_stream
*
)
*
stream
;
s
->
session
=
NULL
;
s
->
channel
=
NULL
;
if
(
!
git__prefixcmp
(
url
,
prefix_ssh
))
{
if
(
!
git__prefixcmp
(
url
,
prefix_ssh
))
{
if
((
error
=
gitno_extract_url_parts
(
&
host
,
&
port
,
&
path
,
&
user
,
&
pass
,
url
,
default_port
))
<
0
)
if
((
error
=
gitno_extract_url_parts
(
&
host
,
&
port
,
&
path
,
&
user
,
&
pass
,
url
,
default_port
))
<
0
)
goto
on_error
;
goto
done
;
}
else
{
}
else
{
if
((
error
=
git_ssh_extract_url_parts
(
&
host
,
&
user
,
url
))
<
0
)
if
((
error
=
git_ssh_extract_url_parts
(
&
host
,
&
user
,
url
))
<
0
)
goto
on_error
;
goto
done
;
port
=
git__strdup
(
default_port
);
port
=
git__strdup
(
default_port
);
GITERR_CHECK_ALLOC
(
port
);
GITERR_CHECK_ALLOC
(
port
);
}
}
if
((
error
=
gitno_connect
(
&
s
->
socket
,
host
,
port
,
0
))
<
0
)
if
((
error
=
gitno_connect
(
&
s
->
socket
,
host
,
port
,
0
))
<
0
)
goto
on_error
;
goto
done
;
if
((
error
=
_git_ssh_session_create
(
&
session
,
s
->
socket
))
<
0
)
if
((
error
=
_git_ssh_session_create
(
&
session
,
s
->
socket
))
<
0
)
goto
on_error
;
goto
done
;
if
(
t
->
owner
->
certificate_check_cb
!=
NULL
)
{
if
(
t
->
owner
->
certificate_check_cb
!=
NULL
)
{
git_cert_hostkey
cert
=
{
0
},
*
cert_ptr
;
git_cert_hostkey
cert
=
{
0
},
*
cert_ptr
;
...
@@ -499,7 +503,8 @@ static int _git_ssh_setup_conn(
...
@@ -499,7 +503,8 @@ static int _git_ssh_setup_conn(
if
(
cert
.
type
==
0
)
{
if
(
cert
.
type
==
0
)
{
giterr_set
(
GITERR_SSH
,
"unable to get the host key"
);
giterr_set
(
GITERR_SSH
,
"unable to get the host key"
);
return
-
1
;
error
=
-
1
;
goto
done
;
}
}
/* We don't currently trust any hostkeys */
/* We don't currently trust any hostkeys */
...
@@ -512,27 +517,27 @@ static int _git_ssh_setup_conn(
...
@@ -512,27 +517,27 @@ static int _git_ssh_setup_conn(
if
(
!
giterr_last
())
if
(
!
giterr_last
())
giterr_set
(
GITERR_NET
,
"user cancelled hostkey check"
);
giterr_set
(
GITERR_NET
,
"user cancelled hostkey check"
);
goto
on_error
;
goto
done
;
}
}
}
}
/* we need the username to ask for auth methods */
/* we need the username to ask for auth methods */
if
(
!
user
)
{
if
(
!
user
)
{
if
((
error
=
request_creds
(
&
cred
,
t
,
NULL
,
GIT_CREDTYPE_USERNAME
))
<
0
)
if
((
error
=
request_creds
(
&
cred
,
t
,
NULL
,
GIT_CREDTYPE_USERNAME
))
<
0
)
goto
on_error
;
goto
done
;
user
=
git__strdup
(((
git_cred_username
*
)
cred
)
->
username
);
user
=
git__strdup
(((
git_cred_username
*
)
cred
)
->
username
);
cred
->
free
(
cred
);
cred
->
free
(
cred
);
cred
=
NULL
;
cred
=
NULL
;
if
(
!
user
)
if
(
!
user
)
goto
on_error
;
goto
done
;
}
else
if
(
user
&&
pass
)
{
}
else
if
(
user
&&
pass
)
{
if
((
error
=
git_cred_userpass_plaintext_new
(
&
cred
,
user
,
pass
))
<
0
)
if
((
error
=
git_cred_userpass_plaintext_new
(
&
cred
,
user
,
pass
))
<
0
)
goto
on_error
;
goto
done
;
}
}
if
((
error
=
list_auth_methods
(
&
auth_methods
,
session
,
user
))
<
0
)
if
((
error
=
list_auth_methods
(
&
auth_methods
,
session
,
user
))
<
0
)
goto
on_error
;
goto
done
;
error
=
GIT_EAUTH
;
error
=
GIT_EAUTH
;
/* if we already have something to try */
/* if we already have something to try */
...
@@ -546,25 +551,25 @@ static int _git_ssh_setup_conn(
...
@@ -546,25 +551,25 @@ static int _git_ssh_setup_conn(
}
}
if
((
error
=
request_creds
(
&
cred
,
t
,
user
,
auth_methods
))
<
0
)
if
((
error
=
request_creds
(
&
cred
,
t
,
user
,
auth_methods
))
<
0
)
goto
on_error
;
goto
done
;
if
(
strcmp
(
user
,
git_cred__username
(
cred
)))
{
if
(
strcmp
(
user
,
git_cred__username
(
cred
)))
{
giterr_set
(
GITERR_SSH
,
"username does not match previous request"
);
giterr_set
(
GITERR_SSH
,
"username does not match previous request"
);
error
=
-
1
;
error
=
-
1
;
goto
on_error
;
goto
done
;
}
}
error
=
_git_ssh_authenticate_session
(
session
,
cred
);
error
=
_git_ssh_authenticate_session
(
session
,
cred
);
}
}
if
(
error
<
0
)
if
(
error
<
0
)
goto
on_error
;
goto
done
;
channel
=
libssh2_channel_open_session
(
session
);
channel
=
libssh2_channel_open_session
(
session
);
if
(
!
channel
)
{
if
(
!
channel
)
{
error
=
-
1
;
error
=
-
1
;
ssh_error
(
session
,
"Failed to open SSH channel"
);
ssh_error
(
session
,
"Failed to open SSH channel"
);
goto
on_error
;
goto
done
;
}
}
libssh2_channel_set_blocking
(
channel
,
1
);
libssh2_channel_set_blocking
(
channel
,
1
);
...
@@ -573,36 +578,25 @@ static int _git_ssh_setup_conn(
...
@@ -573,36 +578,25 @@ static int _git_ssh_setup_conn(
s
->
channel
=
channel
;
s
->
channel
=
channel
;
t
->
current_stream
=
s
;
t
->
current_stream
=
s
;
if
(
cred
)
cred
->
free
(
cred
);
git__free
(
host
);
done:
git__free
(
port
);
if
(
error
<
0
)
{
git__free
(
path
);
if
(
*
stream
)
git__free
(
user
);
ssh_stream_free
(
*
stream
);
git__free
(
pass
);
return
0
;
on_error:
if
(
session
)
s
->
session
=
NULL
;
libssh2_session_free
(
session
);
s
->
channel
=
NULL
;
}
t
->
current_stream
=
NULL
;
if
(
*
stream
)
ssh_stream_free
(
*
stream
);
if
(
cred
)
if
(
cred
)
cred
->
free
(
cred
);
cred
->
free
(
cred
);
git__free
(
host
);
git__free
(
host
);
git__free
(
port
);
git__free
(
port
);
git__free
(
path
);
git__free
(
user
);
git__free
(
user
);
git__free
(
pass
);
git__free
(
pass
);
if
(
session
)
libssh2_session_free
(
session
);
return
error
;
return
error
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment