- 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;
+ }