Fix init/exit logic. Add self-test of it.
This commit is contained in:
parent
2e3f380ff2
commit
fa4017c613
12
src/global.c
12
src/global.c
@ -43,24 +43,24 @@ static int _libssh2_init_flags = 0;
|
||||
|
||||
LIBSSH2_API int libssh2_init(int flags)
|
||||
{
|
||||
if (libssh2_initialized == 0 && !(flags & LIBSSH2_INIT_NO_CRYPTO)) {
|
||||
if (_libssh2_initialized == 0 && !(flags & LIBSSH2_INIT_NO_CRYPTO)) {
|
||||
libssh2_crypto_init();
|
||||
}
|
||||
|
||||
libssh2_initialized++;
|
||||
libssh2_init_flags &= flags;
|
||||
_libssh2_initialized++;
|
||||
_libssh2_init_flags |= flags;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
LIBSSH2_API void libssh2_exit()
|
||||
{
|
||||
if (libssh2_initialized == 0)
|
||||
if (_libssh2_initialized == 0)
|
||||
return;
|
||||
|
||||
libssh2_initialized--;
|
||||
_libssh2_initialized--;
|
||||
|
||||
if (!(libssh2_init_flags & LIBSSH2_INIT_NO_CRYPTO)) {
|
||||
if (!(_libssh2_init_flags & LIBSSH2_INIT_NO_CRYPTO)) {
|
||||
libssh2_crypto_exit();
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* Copyright (C) 2007 The Written Word, Inc.
|
||||
* Copyright (C) 2008 Simon Josefsson
|
||||
* Copyright (C) 2008, 2010 Simon Josefsson
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms,
|
||||
@ -72,6 +72,14 @@ int main(int argc, char *argv[])
|
||||
LIBSSH2_SESSION *session;
|
||||
(void)argv;
|
||||
(void)argc;
|
||||
int rc;
|
||||
|
||||
rc = libssh2_init (LIBSSH2_INIT_NO_CRYPTO);
|
||||
if (rc != 0)
|
||||
{
|
||||
fprintf (stderr, "libssh2_init() failed: %d\n", rc);
|
||||
return 1;
|
||||
}
|
||||
|
||||
session = libssh2_session_init();
|
||||
if (!session)
|
||||
@ -84,5 +92,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
libssh2_session_free(session);
|
||||
|
||||
libssh2_exit ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user