Permalink
Browse files

error checking

  • Loading branch information...
pkrumins committed Aug 5, 2010
1 parent d561df6 commit 0b284e3d49075000a76497f2ebd19f98b407f2da
Showing with 7 additions and 1 deletion.
  1. +7 −1 src/nodepng.cpp
View
@@ -116,7 +116,13 @@ Png::EIO_PngEncode(eio_req *req)
p.encode();
enc_req->png_len = p.get_png_len();
enc_req->png = (char *)malloc(sizeof(*enc_req->png)*enc_req->png_len);
- memcpy(enc_req->png, p.get_png(), enc_req->png_len);
+ if (!enc_req->png) {
+ enc_req->error = strdup("malloc in Png::EIO_PngEncode failed.");
+ return 0;
+ }
+ else {
+ memcpy(enc_req->png, p.get_png(), enc_req->png_len);
+ }
}
catch (const char *err) {
enc_req->error = strdup(err);

0 comments on commit 0b284e3

Please sign in to comment.