]> git.imager.perl.org - imager.git/blobdiff - context.c
avoid a possible sign-extension for offsets/sizes in SGI
[imager.git] / context.c
index 8a281c9d2358b6b27dec785756e688e84c5f43d5..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 */
@@ -195,6 +205,9 @@ im_context_clone(im_context_t ctx, const char *where) {
 
 Allocate a new context-local-storage slot.
 
+C<desctructor> will be called when the context is destroyed if the
+corresponding slot is non-NULL.
+
 =cut
 */