nghttp2_session_*_new: Leave session parameter untouched on failure

This commit is contained in:
Tatsuhiro Tsujikawa 2014-06-25 21:19:12 +09:00
parent 4cbfe5d3d1
commit 55c338d7af
2 changed files with 16 additions and 4 deletions

View File

@ -1564,6 +1564,8 @@ void nghttp2_option_set_peer_max_concurrent_streams(nghttp2_option *option,
* the :member:`nghttp2_session_callbacks.recv_callback` must be * the :member:`nghttp2_session_callbacks.recv_callback` must be
* specified. The other members of |callbacks| can be ``NULL``. * specified. The other members of |callbacks| can be ``NULL``.
* *
* If this function fails, |*session_ptr| is left untouched.
*
* This function returns 0 if it succeeds, or one of the following * This function returns 0 if it succeeds, or one of the following
* negative error codes: * negative error codes:
* *
@ -1587,6 +1589,8 @@ int nghttp2_session_client_new(nghttp2_session **session_ptr,
* the :member:`nghttp2_session_callbacks.recv_callback` must be * the :member:`nghttp2_session_callbacks.recv_callback` must be
* specified. The other members of |callbacks| can be ``NULL``. * specified. The other members of |callbacks| can be ``NULL``.
* *
* If this function fails, |*session_ptr| is left untouched.
*
* This function returns 0 if it succeeds, or one of the following * This function returns 0 if it succeeds, or one of the following
* negative error codes: * negative error codes:
* *

View File

@ -415,14 +415,18 @@ int nghttp2_session_client_new2(nghttp2_session **session_ptr,
const nghttp2_option *option) const nghttp2_option *option)
{ {
int rv; int rv;
nghttp2_session *session;
rv = session_new(session_ptr, callbacks, user_data, 0, option); rv = session_new(&session, callbacks, user_data, 0, option);
if(rv != 0) { if(rv != 0) {
return rv; return rv;
} }
/* IDs for use in client */ /* IDs for use in client */
(*session_ptr)->next_stream_id = 1; session->next_stream_id = 1;
*session_ptr = session;
return 0; return 0;
} }
@ -439,14 +443,18 @@ int nghttp2_session_server_new2(nghttp2_session **session_ptr,
const nghttp2_option *option) const nghttp2_option *option)
{ {
int rv; int rv;
nghttp2_session *session;
rv = session_new(session_ptr, callbacks, user_data, 1, option); rv = session_new(&session, callbacks, user_data, 1, option);
if(rv != 0) { if(rv != 0) {
return rv; return rv;
} }
/* IDs for use in client */ /* IDs for use in client */
(*session_ptr)->next_stream_id = 2; session->next_stream_id = 2;
*session_ptr = session;
return 0; return 0;
} }