CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
46 lines
1.8 KiB
ReStructuredText
46 lines
1.8 KiB
ReStructuredText
.. title:: clang-tidy - bugprone-suspicious-realloc-usage
|
|
|
|
bugprone-suspicious-realloc-usage
|
|
=================================
|
|
|
|
This check finds usages of ``realloc`` where the return value is assigned to
|
|
the same expression as passed to the first argument:
|
|
``p = realloc(p, size);``
|
|
The problem with this construct is that if ``realloc`` fails it returns a
|
|
null pointer but does not deallocate the original memory. If no other variable
|
|
is pointing to it, the original memory block is not available any more for the
|
|
program to use or free. In either case ``p = realloc(p, size);`` indicates bad
|
|
coding style and can be replaced by ``q = realloc(p, size);``.
|
|
|
|
The pointer expression (used at ``realloc``) can be a variable or a field
|
|
member of a data structure, but can not contain function calls or unresolved
|
|
types.
|
|
|
|
In obvious cases when the pointer used at realloc is assigned to another
|
|
variable before the ``realloc`` call, no warning is emitted. This happens only
|
|
if a simple expression in form of ``q = p`` or ``void *q = p`` is found in the
|
|
same function where ``p = realloc(p, ...)`` is found. The assignment has to be
|
|
before the call to realloc (but otherwise at any place) in the same function.
|
|
This suppression works only if ``p`` is a single variable.
|
|
|
|
Examples:
|
|
|
|
.. code-block:: c++
|
|
|
|
struct A {
|
|
void *p;
|
|
};
|
|
|
|
A &getA();
|
|
|
|
void foo(void *p, A *a, int new_size) {
|
|
p = realloc(p, new_size); // warning: 'p' may be set to null if 'realloc' fails, which may result in a leak of the original buffer
|
|
a->p = realloc(a->p, new_size); // warning: 'a->p' may be set to null if 'realloc' fails, which may result in a leak of the original buffer
|
|
getA().p = realloc(getA().p, new_size); // no warning
|
|
}
|
|
|
|
void foo1(void *p, int new_size) {
|
|
void *p1 = p;
|
|
p = realloc(p, new_size); // no warning
|
|
}
|