Persistent mallocs can return NULL (on failure)

This commit is contained in:
Sara Golemon 2004-07-21 02:38:40 +00:00
parent a03447092d
commit ee93ed0aaa
2 changed files with 33 additions and 2 deletions

View File

@ -38,7 +38,7 @@ typedef struct _php_bz2_filter_data {
static void *php_bz2_alloc(void *opaque, int items, int size)
{
return (void *)pemalloc(items * size, ((php_bz2_filter_data*)opaque)->persistent);
return (void *)safe_pemalloc(items, size, 0, ((php_bz2_filter_data*)opaque)->persistent);
}
static void php_bz2_free(void *opaque, void *address)
@ -269,6 +269,10 @@ static php_stream_filter *php_bz2_filter_create(const char *filtername, zval *fi
/* Create this filter */
data = pecalloc(1, sizeof(php_bz2_filter_data), persistent);
if (!data) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %d bytes.", sizeof(php_bz2_filter_data));
return NULL;
}
/* Circular reference */
data->strm.opaque = (void *) data;
@ -278,8 +282,19 @@ static php_stream_filter *php_bz2_filter_create(const char *filtername, zval *fi
data->persistent = persistent;
data->strm.avail_out = data->outbuf_len = data->inbuf_len = 2048;
data->strm.next_in = data->inbuf = (char *) pemalloc(data->inbuf_len, persistent);
if (!data->inbuf) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %d bytes.", data->inbuf_len);
pefree(data, persistent);
return NULL;
}
data->strm.avail_in = 0;
data->strm.next_out = data->outbuf = (char *) pemalloc(data->outbuf_len, persistent);
if (!data->outbuf) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %d bytes.", data->outbuf_len);
pefree(data->inbuf, persistent);
pefree(data, persistent);
return NULL;
}
if (strcasecmp(filtername, "bzip2.decompress") == 0) {
int smallFootprint = 0;

View File

@ -39,7 +39,7 @@ typedef struct _php_zlib_filter_data {
static voidpf php_zlib_alloc(voidpf opaque, uInt items, uInt size)
{
return (voidpf)pemalloc(items * size, ((php_zlib_filter_data*)opaque)->persistent);
return (voidpf)safe_pemalloc(items, size, 0, ((php_zlib_filter_data*)opaque)->persistent);
}
static void php_zlib_free(voidpf opaque, voidpf address)
@ -274,6 +274,10 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f
/* Create this filter */
data = pecalloc(1, sizeof(php_zlib_filter_data), persistent);
if (!data) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %d bytes.", data->inbuf_len);
return NULL;
}
/* Circular reference */
data->strm.opaque = (voidpf) data;
@ -282,8 +286,20 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f
data->strm.zfree = (free_func) php_zlib_free;
data->strm.avail_out = data->outbuf_len = data->inbuf_len = 2048;
data->strm.next_in = data->inbuf = (Bytef *) pemalloc(data->inbuf_len, persistent);
if (!data->inbuf) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %d bytes.", data->inbuf_len);
pefree(data, persistent);
return NULL;
}
data->strm.avail_in = 0;
data->strm.next_out = data->outbuf = (Bytef *) pemalloc(data->outbuf_len, persistent);
if (!data->outbuf) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %d bytes.", data->inbuf_len);
pefree(data->inbuf, persistent);
pefree(data, persistent);
return NULL;
}
data->strm.data_type = Z_ASCII;
if (strcasecmp(filtername, "zlib.inflate") == 0) {