Browse Source

return CAIRO_STATUS_NO_MEMORY on failed {re,m}alloc()

v1.x
Tj Holowaychuk 14 years ago
parent
commit
2391844f23
  1. 4
      src/Canvas.cc

4
src/Canvas.cc

@ -6,6 +6,7 @@
//
#include "Canvas.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <node_buffer.h>
@ -116,13 +117,14 @@ Canvas::SetHeight(Local<String> prop, Local<Value> val, const AccessorInfo &info
static cairo_status_t
toBuffer(void *c, const uint8_t *data, unsigned len) {
closure_t *closure = (closure_t *) c;
// TODO: mem handling
if (closure->len) {
closure->data = (uint8_t *) realloc(closure->data, closure->len + len);
if (NULL == closure->data) return CAIRO_STATUS_NO_MEMORY;
memcpy(closure->data + closure->len, data, len);
closure->len += len;
} else {
closure->data = (uint8_t *) malloc(len);
if (NULL == closure->data) return CAIRO_STATUS_NO_MEMORY;
memcpy(closure->data, data, len);
closure->len += len;
}

Loading…
Cancel
Save