]> git.imager.perl.org - imager.git/commitdiff
handle failure to clone the log filehandle when cloning the Imager context
authorTony Cook <tony@develop-help.com>
Sun, 6 Jan 2019 04:03:55 +0000 (15:03 +1100)
committerTony Cook <tony@develop-help.com>
Sun, 6 Jan 2019 04:03:55 +0000 (15:03 +1100)
Changes
Imager.xs
context.c

diff --git a/Changes b/Changes
index 31b4d7fe3325005fc3fcb5ea265de15dc510974b..7bf5764d6ee554889e9efa9ee767b6b43d6273fe 100644 (file)
--- a/Changes
+++ b/Changes
@@ -102,6 +102,9 @@ High severity:
  - avoid discarding the value of i_io_getc() when scanning numbers in
    pnm.c.  CID 185293.
 
+ - handle failure to clone the log filehandle when cloning the Imager
+   context object on thread creation.  CID 185294.
+
 [1] The first two build submissions ended up at the end of a ~400
 build queue, and seemed to have been cancelled by Coverity.  A build
 submitted on NYE went through in minutes.
index cac322d52548c1752aa8fe4fee48deec6f1393bb..14e752d8a260f946169e491452e2776a7d70bd63 100644 (file)
--- a/Imager.xs
+++ b/Imager.xs
@@ -4197,6 +4197,9 @@ im_context_CLONE(...)
       /* the following sv_setref_pv() will free this inc */
       im_context_refinc(MY_CXT.ctx, "CLONE");
       MY_CXT.ctx = im_context_clone(MY_CXT.ctx, "CLONE");
+      if (MY_CXT.ctx == NULL) {
+        croak("Failed to clone Imager context");
+      }
       sv_setref_pv(get_sv("Imager::_context", GV_ADD), "Imager::Context", MY_CXT.ctx);
 
 #endif
index 0598a6abf3669bc67aac931fde873d99cdff302f..8baa60e0dd118e73da1ba3e5156add867b5e4aa5 100644 (file)
--- a/context.c
+++ b/context.c
@@ -162,10 +162,20 @@ im_context_clone(im_context_t ctx, const char *where) {
   if (ctx->lg_file) {
     if (ctx->own_log) {
       int newfd = dup(fileno(ctx->lg_file));
-      nctx->own_log = 1;
-      nctx->lg_file = fdopen(newfd, "w");
-      if (nctx->lg_file)
-       setvbuf(nctx->lg_file, NULL, _IONBF, BUFSIZ);
+      if (newfd >= 0) {
+        nctx->own_log = 1;
+        nctx->lg_file = fdopen(newfd, "w");
+        if (nctx->lg_file)
+         setvbuf(nctx->lg_file, NULL, _IONBF, BUFSIZ);
+      }
+      else {
+#ifdef IMAGER_TRACE_CONTEXT
+       perror("im_context:failed to clone log");
+#endif
+       free(nctx->slots);
+       free(nctx);
+       return NULL;
+      }
     }
     else {
       /* stderr */