--max-memory
- Accepted by
opengrep scan,opengrep ci,opengrep test- Value
INT, in MiB- Default
0, no limit
Limits the memory used by the analysis of one file, and by the cross-file analysis. When the limit is exceeded, Opengrep abandons the file, logs the warning ExceededMemoryLimit on <file>, counts the file as partially analyzed, and continues. The scan still exits with status 0, unless --strict is given.
0, the default, sets no limit. The value is in MiB.
Each of the --jobs workers analyzes its own files, so a smaller number of workers also reduces the memory that a scan uses.
Examples
A limit too small to analyze anything
rule.yaml
rules: - id: find-eval pattern: eval(...) message: found eval languages: [python] severity: WARNINGCommand and result
$ seq 20000 | sed 's/.*/x& = f(&)/' > big.py && echo 'eval(1)' >> big.py
$ opengrep scan -q --config rule.yaml --files-with-matches big.py
big.py
$ opengrep scan -q --config rule.yaml --files-with-matches --max-memory 1 big.py
$ opengrep scan --config rule.yaml --max-memory 1 big.py 2>&1 >/dev/null | grep ExceededMemoryLimit
warning ExceededMemoryLimit on big.pyWith the limit, the third command prints nothing: the file was abandoned and has no findings. The warning names the file, and the summary counts it as partially analyzed.