Skip to content

Commit 787c1a3

Browse files
committed
don't leak/clean up on errors
1 parent 287f0f1 commit 787c1a3

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

src/packet.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,19 +1149,23 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
11491149
buf.dataptr++; /* Advance past packet type */
11501150

11511151
if(_libssh2_get_u32(&buf, &channel)) {
1152-
return _libssh2_error(session, LIBSSH2_ERROR_PROTO,
1153-
"Unexpected channel value.");
1152+
rc = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
1153+
"Unexpected channel value.");
1154+
goto clean_exit;
11541155
}
1156+
11551157
if(_libssh2_get_string(&buf, &request, &r_len)) {
1156-
return _libssh2_error(session, LIBSSH2_ERROR_PROTO,
1157-
"Unexpected request value.");
1158+
rc = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
1159+
"Unexpected request value.");
1160+
goto clean_exit;
11581161
}
11591162

11601163
len = (uint32_t)r_len;
11611164

11621165
if(_libssh2_get_byte(&buf, &want_reply)) {
1163-
return _libssh2_error(session, LIBSSH2_ERROR_PROTO,
1164-
"Unexpected want reply value.");
1166+
rc = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
1167+
"Unexpected want reply value.");
1168+
goto clean_exit;
11651169
}
11661170

11671171
_libssh2_debug((session,
@@ -1241,6 +1245,9 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
12411245
return rc;
12421246
}
12431247
}
1248+
1249+
clean_exit:
1250+
12441251
LIBSSH2_FREE(session, data);
12451252
session->packAdd_state = libssh2_NB_state_idle;
12461253
return rc;

0 commit comments

Comments
 (0)