Process-terminating call outside main

ID

c.correctness.terminating_function_call

Severity

low

Remediation Complexity

medium

Remediation Risk

medium

Remediation Effort

medium

Resource

Error Handling

Language

C / C++

Description

This call ends the whole process immediately, from code that is not main. Callers of this function have no chance to release resources, log the failure in context, or decide whether termination is even the right response. Report the error to the caller (a return code or an exception) and let the top-level main decide whether to terminate.

Rationale

This call ends the whole process immediately, from code that is not main. Callers of this function have no chance to release resources, log the failure in context, or decide whether termination is even the right response. Report the error to the caller (a return code or an exception) and let the top-level main decide whether to terminate.

The following code illustrates the pattern detected by this rule:

void helper(int code) {
  if (code < 0) {
    // FLAGGED: Process-terminating call outside main
    abort();
  }
  if (code == 0) {
    // FLAGGED: Process-terminating call outside main
    exit(1);
  }
  if (code == 1) {
    // FLAGGED: Process-terminating call outside main
    quick_exit(1);
  }
  if (code == 2) {
    // FLAGGED: Process-terminating call outside main
    std::terminate();
  }
}

Remediation

Follow secure coding practices and review the references below for detailed remediation guidance.

Configuration

This detector does not need any configuration.

References

© 2026 Xygeni. All rights reserved