espressif / clang-tidy-runner

MIT License
9 stars 5 forks source link

`idf.py clang-check` Cannot find intentional memory leak error (IDFGH-11244) #41

Closed kayasemih closed 1 year ago

kayasemih commented 1 year ago

IDF version.

v4.4.4

Espressif SoC revision.

ESP32-D0WD-V3 (revision 3)

Operating System used.

MacOS

How did you build your project?

Command line with idf.py

IDE being used

VS Code IDE

Build System

CMake

Development Kit.

ESP32 WROVER-IE on Custom Board

The error I intentionally made on esp-idf's own sample project in the directory I specified is as follows; /esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/main/simple_client.cpp

    void *x = malloc(2);
    x = 0;

I have attached the warning.txt file generated when I run the project by idf.py clang-check.

warnings.txt

Logging is as follows;

command "/Users/Inthecask/.espressif/python_env/idf4.4_py3.11_env/bin/python /usr/local/bin/run-clang-tidy.py -p build .*" gives the following warnings with exitcode 1:
5 warnings and 1 error generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_primitives_freertos.cpp.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
5 warnings and 1 error generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_vfs_uart_creator.cpp.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
5 warnings and 1 error generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_vfs_socket_creator.cpp.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
5 warnings and 3 errors generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_term_fs.cpp.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
5 warnings and 1 error generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_dce.cpp.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
5 warnings and 3 errors generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_modules.cpp.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
5 warnings and 13 errors generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_dte.cpp.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
5 warnings and 1 error generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_term_uart.cpp.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
5 warnings and 2 errors generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_netif.cpp.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
5 warnings and 3 errors generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_uart.cpp.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
7 warnings and 3 errors generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/main/simple_client.cpp.
Suppressed 7 warnings (7 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
7 warnings and 3 errors generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_factory.cpp.
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
6 warnings and 20 errors generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_command_library.cpp.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
6 warnings and 6 errors generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_api.cpp.
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
7 warnings and 3 errors generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/main/simple_mqtt_client.cpp.
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
6 warnings and 5 errors generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_c_api.cpp.
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
6 warnings and 3 errors generated.
Error while processing /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/managed_components/espressif__esp_modem/src/esp_modem_cmux.cpp.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).

clang-tidy report generated: /Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/warnings.txt
color outputs in "/Users/Inthecask/esp/esp-idf/examples/cxx/experimental/esp_modem_cxx/warnings.txt" are eliminated.

The situation I noticed is thatIDF Clang-Tidy does not do a bad job between 30-40 LOC. But it doesn't notice memory leaks, which I would expect it to notice in slightly more complex projects. Is this some kind of bug? How can it be used more effectively? Please correct me if I'm wrong, I intend to use any static code analyzer to alert me to bugs I'm not noticing and areas where I need to be careful. If it can't do its job, there is no point in using it. You mentioned earlier that IDF Clang-Tidy is still under development. I appreciate your efforts, but as a user, can we conclude that it is not ready for use yet?

main.zip

radimkarnis commented 1 year ago

Hello @semihkaya0941,

there is a default set of checks enabled when you run Clang-Tidy, you can find them in the log listed under Enabled checks: when you run the tool.

We currently working on a patch to enable more checks.

In the meantime, it is possible to use the --run-clang-tidy-options option to enable additional Clang-Tidy Checks (full list of available checks is here).

e.g.: idf.py clang-check --run-clang-tidy-options="-checks=bugprone-undefined-memory-manipulation,readability-avoid-const-params-in-decls" will also run the following checks:

This might enable you to run a suitable check to detect the memory leak, but I am not 100% sure about it. Maybe the leak was not detected because of other reasons.