]> git.imager.perl.org - imager.git/blobdiff - context.c
on't check if the unsigned size supplied to im_set_image_file_limits() is negative
[imager.git] / context.c
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));
   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 */
     }
     else {
       /* stderr */