X-Git-Url: http://git.imager.perl.org/imager.git/blobdiff_plain/d7506bda0b8850dc775bf565969a107ec457e757..e1c0692925:/context.c diff --git a/context.c b/context.c index 8a281c9d..8baa60e0 100644 --- 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 will be called when the context is destroyed if the +corresponding slot is non-NULL. + =cut */