Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix possible segfault in php_smb_ops_close when called after php_smb_… #82

Merged
merged 1 commit into from
Feb 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion smb_streams.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,22 @@ static void php_smb_pool_drop(php_smbclient_state *state TSRMLS_DC)
for (pool = SMBCLIENT_G(pool_first); pool; pool = pool->next) {
if (pool->state == state) {
pool->nb--;
return;
}
}

/* Not found (after php_smb_pool_cleanup) so close it */
php_smbclient_state_free(state TSRMLS_CC);
}

void php_smb_pool_cleanup(TSRMLS_D) {
struct _php_smb_pool *pool;

pool = SMBCLIENT_G(pool_first);
while (pool) {
php_smbclient_state_free(pool->state TSRMLS_CC);
if (!pool->nb) { /* Keep it when still used */
php_smbclient_state_free(pool->state TSRMLS_CC);
}
pool = pool->next;
efree(pool);
}
Expand All @@ -169,6 +175,7 @@ static int php_smb_ops_close(php_stream *stream, int close_handle TSRMLS_DC)
if (!self) {
return EOF;
}

if (close_handle) {
if (self->handle) {
smbc_close = smbc_getFunctionClose(self->state->ctx);
Expand Down