-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A simple function using LIBSSH2_ALLOC + memset, since this pattern was used in multiple places and this simplies code in general.
- Loading branch information
Showing
12 changed files
with
39 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* Copyright (c) 2004-2007, Sara Golemon <[email protected]> | ||
* Copyright (c) 2010, Daniel Stenberg <[email protected]> | ||
* Copyright (c) 2010-2014, Daniel Stenberg <[email protected]> | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, | ||
|
@@ -141,13 +141,12 @@ comp_method_zlib_init(LIBSSH2_SESSION * session, int compr, | |
z_stream *strm; | ||
int status; | ||
|
||
strm = LIBSSH2_ALLOC(session, sizeof(z_stream)); | ||
strm = LIBSSH2_CALLOC(session, sizeof(z_stream)); | ||
if (!strm) { | ||
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, | ||
"Unable to allocate memory for " | ||
"zlib compression/decompression"); | ||
} | ||
memset(strm, 0, sizeof(z_stream)); | ||
|
||
strm->opaque = (voidpf) session; | ||
strm->zalloc = (alloc_func) comp_method_zlib_alloc; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* Copyright (c) 2004-2006, Sara Golemon <[email protected]> | ||
* Copyright (c) 2009 by Daniel Stenberg | ||
* Copyright (c) 2009-2014 by Daniel Stenberg | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, | ||
|
@@ -347,13 +347,12 @@ hostkey_method_ssh_dss_signv(LIBSSH2_SESSION * session, | |
libssh2_sha1_ctx ctx; | ||
int i; | ||
|
||
*signature = LIBSSH2_ALLOC(session, 2 * SHA_DIGEST_LENGTH); | ||
*signature = LIBSSH2_CALLOC(session, 2 * SHA_DIGEST_LENGTH); | ||
if (!*signature) { | ||
return -1; | ||
} | ||
|
||
*signature_len = 2 * SHA_DIGEST_LENGTH; | ||
memset(*signature, 0, 2 * SHA_DIGEST_LENGTH); | ||
|
||
libssh2_sha1_init(&ctx); | ||
for(i = 0; i < veccount; i++) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* Copyright (c) 2004-2008, 2010, Sara Golemon <[email protected]> | ||
* Copyright (c) 2009-2011 by Daniel Stenberg | ||
* Copyright (c) 2009-2014 by Daniel Stenberg | ||
* Copyright (c) 2010 Simon Josefsson | ||
* All rights reserved. | ||
* | ||
|
@@ -152,6 +152,7 @@ static inline int writev(int sock, struct iovec *iov, int nvecs) | |
|
||
#define LIBSSH2_ALLOC(session, count) \ | ||
session->alloc((count), &(session)->abstract) | ||
#define LIBSSH2_CALLOC(session, count) _libssh2_calloc(session, count) | ||
#define LIBSSH2_REALLOC(session, ptr, count) \ | ||
((ptr) ? session->realloc((ptr), (count), &(session)->abstract) : \ | ||
session->alloc((count), &(session)->abstract)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* Copyright (c) 2004-2007 Sara Golemon <[email protected]> | ||
* Copyright (c) 2009-2010 by Daniel Stenberg | ||
* Copyright (c) 2009-2014 by Daniel Stenberg | ||
* Copyright (c) 2010 Simon Josefsson | ||
* All rights reserved. | ||
* | ||
|
@@ -619,3 +619,12 @@ int __cdecl _libssh2_gettimeofday(struct timeval *tp, void *tzp) | |
|
||
|
||
#endif | ||
|
||
void *_libssh2_calloc(LIBSSH2_SESSION* session, size_t size) | ||
{ | ||
void *p = LIBSSH2_ALLOC(session, size); | ||
if(p) { | ||
memset(p, 0, size); | ||
} | ||
return p; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* Copyright (c) 2004-2007, Sara Golemon <[email protected]> | ||
* Copyright (c) 2005,2006 Mikhail Gusarov | ||
* Copyright (c) 2009-2013 by Daniel Stenberg | ||
* Copyright (c) 2009-2014 by Daniel Stenberg | ||
* Copyright (c) 2010 Simon Josefsson | ||
* All rights reserved. | ||
* | ||
|
@@ -139,7 +139,7 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data, | |
break; | ||
} | ||
|
||
channel = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_CHANNEL)); | ||
channel = LIBSSH2_CALLOC(session, sizeof(LIBSSH2_CHANNEL)); | ||
if (!channel) { | ||
_libssh2_error(session, LIBSSH2_ERROR_ALLOC, | ||
"Unable to allocate a channel for " | ||
|
@@ -150,8 +150,6 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data, | |
} | ||
listen_state->channel = channel; | ||
|
||
memset(channel, 0, sizeof(LIBSSH2_CHANNEL)); | ||
|
||
channel->session = session; | ||
channel->channel_type_len = sizeof("forwarded-tcpip") - 1; | ||
channel->channel_type = LIBSSH2_ALLOC(session, | ||
|
@@ -299,14 +297,13 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data, | |
|
||
if (session->x11) { | ||
if (x11open_state->state == libssh2_NB_state_allocated) { | ||
channel = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_CHANNEL)); | ||
channel = LIBSSH2_CALLOC(session, sizeof(LIBSSH2_CHANNEL)); | ||
if (!channel) { | ||
_libssh2_error(session, LIBSSH2_ERROR_ALLOC, | ||
"allocate a channel for new connection"); | ||
failure_code = SSH_OPEN_RESOURCE_SHORTAGE; | ||
goto x11_exit; | ||
} | ||
memset(channel, 0, sizeof(LIBSSH2_CHANNEL)); | ||
|
||
channel->session = session; | ||
channel->channel_type_len = sizeof("x11") - 1; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* Copyright (c) 2004-2008, Sara Golemon <[email protected]> | ||
* Copyright (c) 2007 Eli Fant <[email protected]> | ||
* Copyright (c) 2009-2013 by Daniel Stenberg | ||
* Copyright (c) 2009-2014 by Daniel Stenberg | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, | ||
|
@@ -781,13 +781,12 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) | |
|
||
sftp_handle = | ||
session->sftpInit_sftp = | ||
LIBSSH2_ALLOC(session, sizeof(LIBSSH2_SFTP)); | ||
LIBSSH2_CALLOC(session, sizeof(LIBSSH2_SFTP)); | ||
if (!sftp_handle) { | ||
_libssh2_error(session, LIBSSH2_ERROR_ALLOC, | ||
"Unable to allocate a new SFTP structure"); | ||
goto sftp_init_error; | ||
} | ||
memset(sftp_handle, 0, sizeof(LIBSSH2_SFTP)); | ||
sftp_handle->channel = session->sftpInit_channel; | ||
sftp_handle->request_id = 0; | ||
|
||
|
@@ -1173,14 +1172,13 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename, | |
return NULL; | ||
} | ||
|
||
fp = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_SFTP_HANDLE)); | ||
fp = LIBSSH2_CALLOC(session, sizeof(LIBSSH2_SFTP_HANDLE)); | ||
if (!fp) { | ||
_libssh2_error(session, LIBSSH2_ERROR_ALLOC, | ||
"Unable to allocate new SFTP handle structure"); | ||
LIBSSH2_FREE(session, data); | ||
return NULL; | ||
} | ||
memset(fp, 0, sizeof(LIBSSH2_SFTP_HANDLE)); | ||
fp->handle_type = open_file ? LIBSSH2_SFTP_HANDLE_FILE : | ||
LIBSSH2_SFTP_HANDLE_DIR; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters