Skip to content

Commit be61597

Browse files
laruenceweltling
authored andcommitted
Fix various bugs in interbase
Also read: https://marc.info/?l=php-internals&m=145077389117375&w=2
1 parent fb9f731 commit be61597

File tree

9 files changed

+136
-143
lines changed

9 files changed

+136
-143
lines changed

ibase_blobs.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static void _php_ibase_free_blob(zend_resource *rsrc) /* {{{ */
3636
{
3737
ibase_blob *ib_blob = (ibase_blob *)rsrc->ptr;
3838

39-
if (ib_blob->bl_handle != NULL) { /* blob open*/
39+
if (ib_blob->bl_handle != 0) { /* blob open*/
4040
if (isc_cancel_blob(IB_STATUS, &ib_blob->bl_handle)) {
4141
_php_ibase_module_error("You can lose data. Close any blob after reading from or "
4242
"writing to it. Use ibase_blob_close() before calling ibase_close()");
@@ -216,7 +216,7 @@ PHP_FUNCTION(ibase_blob_create)
216216
PHP_IBASE_LINK_TRANS(link, ib_link, trans);
217217

218218
ib_blob = (ibase_blob *) emalloc(sizeof(ibase_blob));
219-
ib_blob->bl_handle = NULL;
219+
ib_blob->bl_handle = 0;
220220
ib_blob->type = BLOB_INPUT;
221221

222222
if (isc_create_blob(IB_STATUS, &ib_link->handle, &trans->handle, &ib_blob->bl_handle, &ib_blob->bl_qd)) {
@@ -261,7 +261,7 @@ PHP_FUNCTION(ibase_blob_open)
261261
PHP_IBASE_LINK_TRANS(link, ib_link, trans);
262262

263263
ib_blob = (ibase_blob *) emalloc(sizeof(ibase_blob));
264-
ib_blob->bl_handle = NULL;
264+
ib_blob->bl_handle = 0;
265265
ib_blob->type = BLOB_OUTPUT;
266266

267267
do {
@@ -361,15 +361,15 @@ static void _php_ibase_blob_end(INTERNAL_FUNCTION_PARAMETERS, int bl_end) /* {{{
361361
RETURN_FALSE;
362362
}
363363
}
364-
ib_blob->bl_handle = NULL;
364+
ib_blob->bl_handle = 0;
365365

366366
RETVAL_NEW_STR(_php_ibase_quad_to_string(ib_blob->bl_qd));
367367
} else { /* discard created blob */
368368
if (isc_cancel_blob(IB_STATUS, &ib_blob->bl_handle)) {
369369
_php_ibase_error();
370370
RETURN_FALSE;
371371
}
372-
ib_blob->bl_handle = NULL;
372+
ib_blob->bl_handle = 0;
373373
RETVAL_TRUE;
374374
}
375375
zend_list_delete(Z_RES_P(blob_arg));
@@ -401,7 +401,7 @@ PHP_FUNCTION(ibase_blob_info)
401401
zval *link = NULL;
402402
ibase_db_link *ib_link;
403403
ibase_trans *trans = NULL;
404-
ibase_blob ib_blob = { NULL, BLOB_INPUT };
404+
ibase_blob ib_blob = { 0, BLOB_INPUT };
405405
IBASE_BLOBINFO bl_info;
406406

407407
RESET_ERRMSG;
@@ -477,7 +477,7 @@ PHP_FUNCTION(ibase_blob_echo)
477477
zval *link = NULL;
478478
ibase_db_link *ib_link;
479479
ibase_trans *trans = NULL;
480-
ibase_blob ib_blob_id = { NULL, BLOB_OUTPUT };
480+
ibase_blob ib_blob_id = { 0, BLOB_OUTPUT };
481481
char bl_data[IBASE_BLOB_SEG];
482482
unsigned short seg_len;
483483

@@ -538,7 +538,7 @@ PHP_FUNCTION(ibase_blob_import)
538538
zval *link = NULL, *file;
539539
int size;
540540
unsigned short b;
541-
ibase_blob ib_blob = { NULL, 0 };
541+
ibase_blob ib_blob = { 0, 0 };
542542
ibase_db_link *ib_link;
543543
ibase_trans *trans = NULL;
544544
char bl_data[IBASE_BLOB_SEG];

ibase_events.c

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ void _php_ibase_free_event(ibase_event *event) /* {{{ */
4545
if (event->link != NULL) {
4646
ibase_event **node;
4747

48-
if (event->link->handle != NULL &&
48+
zend_list_delete(event->link_res);
49+
if (event->link->handle != 0 &&
4950
isc_cancel_events(IB_STATUS, &event->link->handle, &event->event_id)) {
5051
_php_ibase_error();
5152
}
@@ -62,7 +63,9 @@ void _php_ibase_free_event(ibase_event *event) /* {{{ */
6263
_php_ibase_event_free(event->event_buffer,event->result_buffer);
6364

6465
for (i = 0; i < event->event_count; ++i) {
65-
efree(event->events[i]);
66+
if (event->events[i]) {
67+
efree(event->events[i]);
68+
}
6669
}
6770
efree(event->events);
6871
}
@@ -150,7 +153,7 @@ PHP_FUNCTION(ibase_wait_event)
150153
if (ZEND_NUM_ARGS() > 15) {
151154
WRONG_PARAM_COUNT;
152155
}
153-
if ((ib_link = (ibase_db_link *)zend_fetch_resource2_ex(IBG(default_link), "InterBase link", le_link, le_plink)) == NULL) {
156+
if ((ib_link = (ibase_db_link *)zend_fetch_resource2(IBG(default_link), "InterBase link", le_link, le_plink)) == NULL) {
154157
RETURN_FALSE;
155158
}
156159
}
@@ -190,8 +193,6 @@ PHP_FUNCTION(ibase_wait_event)
190193
static isc_callback _php_ibase_callback(ibase_event *event, /* {{{ */
191194
unsigned short buffer_size, char *result_buf)
192195
{
193-
zval *res;
194-
195196
/* this function is called asynchronously by the Interbase client library. */
196197
TSRMLS_FETCH_FROM_CTX(event->thread_ctx);
197198

@@ -211,15 +212,14 @@ static isc_callback _php_ibase_callback(ibase_event *event, /* {{{ */
211212
/* copy the updated results into the result buffer */
212213
memcpy(event->result_buffer, result_buf, buffer_size);
213214

214-
res = zend_hash_index_find(&EG(regular_list), event->link_res_id);
215-
ZVAL_RES(&args[1], Z_RES_P(res));
215+
ZVAL_RES(&args[1], event->link_res);
216216

217217
/* find out which event occurred */
218218
isc_event_counts(occurred_event, buffer_size, event->event_buffer, event->result_buffer);
219219
for (i = 0; i < event->event_count; ++i) {
220220
if (occurred_event[i]) {
221221
ZVAL_STRING(&args[0], event->events[i]);
222-
efree(event->events[i]);
222+
//efree(event->events[i]);
223223
break;
224224
}
225225
}
@@ -262,7 +262,8 @@ PHP_FUNCTION(ibase_set_event_handler)
262262
ibase_db_link *ib_link;
263263
ibase_event *event;
264264
unsigned short i = 1, buffer_size;
265-
int link_res_id, num_args;
265+
int num_args;
266+
zend_resource *link_res;
266267

267268
RESET_ERRMSG;
268269

@@ -291,8 +292,7 @@ PHP_FUNCTION(ibase_set_event_handler)
291292
RETURN_FALSE;
292293
}
293294

294-
convert_to_long_ex(&args[0]);
295-
link_res_id = Z_LVAL(args[0]);
295+
link_res = Z_RES(args[0]);
296296

297297
} else {
298298
/* callback, event_1 [, ... event_15]
@@ -304,10 +304,10 @@ PHP_FUNCTION(ibase_set_event_handler)
304304

305305
cb_arg = &args[0];
306306

307-
if ((ib_link = (ibase_db_link *)zend_fetch_resource2_ex(IBG(default_link), "InterBase link", le_link, le_plink)) == NULL) {
307+
if ((ib_link = (ibase_db_link *)zend_fetch_resource2(IBG(default_link), "InterBase link", le_link, le_plink)) == NULL) {
308308
RETURN_FALSE;
309309
}
310-
link_res_id = IBG(default_link);
310+
link_res = IBG(default_link);
311311
}
312312

313313
/* get the callback */
@@ -321,17 +321,22 @@ PHP_FUNCTION(ibase_set_event_handler)
321321
/* allocate the event resource */
322322
event = (ibase_event *) safe_emalloc(sizeof(ibase_event), 1, 0);
323323
TSRMLS_SET_CTX(event->thread_ctx);
324-
event->link_res_id = link_res_id;
324+
event->link_res = link_res;
325+
GC_REFCOUNT(link_res)++;
325326
event->link = ib_link;
326327
event->event_count = 0;
327328
event->state = NEW;
328-
event->events = (char **) safe_emalloc(sizeof(char *),ZEND_NUM_ARGS()-i,0);
329+
event->events = (char **) safe_emalloc(sizeof(char *), 15, 0);
329330

330331
ZVAL_DUP(&event->callback, cb_arg);
331332

332-
for (; i < ZEND_NUM_ARGS(); ++i) {
333-
convert_to_string_ex(&args[i]);
334-
event->events[event->event_count++] = estrdup(Z_STRVAL(args[i]));
333+
for (; i < 15; ++i) {
334+
if (i < ZEND_NUM_ARGS()) {
335+
convert_to_string_ex(&args[i]);
336+
event->events[event->event_count++] = estrdup(Z_STRVAL(args[i]));
337+
} else {
338+
event->events[i] = NULL;
339+
}
335340
}
336341

337342
/* fills the required data structure with information about the events */

0 commit comments

Comments
 (0)