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 */
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
*/