Skip to content

Commit 234f102

Browse files
committed
improvements in handling of callback
1 parent 208932b commit 234f102

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

git2_php_util.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030

3131
// all remote callbacks have the same payload, so this makes a large structure
3232
struct git2_remote_callbacks_payload {
33-
zval *credentials_callback;
33+
zval credentials_callback;
3434
zend_fcall_info_cache fci_cache;
3535
};
3636

3737
int git2_callback_credentials_call(git_cred **cred, const char *url, const char *username_from_url, unsigned int allowed_types, void *payload) {
3838
struct git2_remote_callbacks_payload *p = (struct git2_remote_callbacks_payload*)payload;
39-
if (p->credentials_callback == NULL) return 1; // ??
39+
if (Z_ISUNDEF(p->credentials_callback)) return 1; // ??
4040

4141
zend_fcall_info fci;
4242
zval argv[3];
@@ -50,7 +50,7 @@ int git2_callback_credentials_call(git_cred **cred, const char *url, const char
5050
fci.size = sizeof(fci);
5151
fci.function_table = EG(function_table);
5252
fci.object = NULL;
53-
ZVAL_COPY_VALUE(&fci.function_name, p->credentials_callback);
53+
ZVAL_COPY_VALUE(&fci.function_name, &p->credentials_callback);
5454
fci.retval = &retval;
5555
fci.param_count = 3;
5656
fci.params = argv;
@@ -70,8 +70,10 @@ int git2_callback_credentials_call(git_cred **cred, const char *url, const char
7070
git_cred *c = git2_cred_take_from_zval(&retval); // will return NULL if not a cred object or used more than once
7171
if (c) {
7272
*cred = c;
73+
zval_ptr_dtor(&retval);
7374
return 0;
7475
}
76+
zval_ptr_dtor(&retval);
7577
return 1;
7678
} else {
7779
return 1;
@@ -89,7 +91,12 @@ static void git2_callback_credentials_set(git_cred_acquire_cb *cb, void **payloa
8991
p = (struct git2_remote_callbacks_payload*)*payload;
9092
}
9193

92-
p->credentials_callback = callback;
94+
if (!Z_ISUNDEF(p->credentials_callback)) {
95+
zval_ptr_dtor(&p->credentials_callback);
96+
p->fci_cache = empty_fcall_info_cache;
97+
}
98+
99+
ZVAL_COPY(&p->credentials_callback, callback);
93100
*cb = git2_callback_credentials_call;
94101
}
95102

0 commit comments

Comments
 (0)