mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-14 05:16:18 +01:00
garray: Change free/unref semantics under static analysis
Recent changes to `GPtrArray` and/or Coverity mean that Coverity is now assuming that `g_ptr_array_free (my_array, TRUE)` can leak memory. This is true in the case that `g_ptr_array_ref (my_array)` has been called elsewhere, but Coverity never actually verifies that. Very little (or no?) GLib code mixes `g_ptr_array_free()` with `g_ptr_array_{ref,unref}()`, so this isn’t a problem in practice. However, it has created a hundred or more false positives in Coverity (as pointer arrays are widely used within GLib and GIO), which is a complete pain. Before taking the dramatic step of ditching Coverity due to its atrocious false positive rate, let’s try changing the semantics of `g_ptr_array_free()` only when running under Coverity. Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
This commit is contained in:
parent
14f4b38fb1
commit
423bcab9f4
@ -1555,9 +1555,14 @@ g_ptr_array_free (GPtrArray *array,
|
|||||||
|
|
||||||
/* if others are holding a reference, preserve the wrapper but
|
/* if others are holding a reference, preserve the wrapper but
|
||||||
* do free/return the data
|
* do free/return the data
|
||||||
|
*
|
||||||
|
* Coverity doesn’t understand this and assumes it’s a leak, so comment this
|
||||||
|
* out.
|
||||||
*/
|
*/
|
||||||
|
#ifndef __COVERITY__
|
||||||
if (!g_atomic_ref_count_dec (&rarray->ref_count))
|
if (!g_atomic_ref_count_dec (&rarray->ref_count))
|
||||||
flags |= PRESERVE_WRAPPER;
|
flags |= PRESERVE_WRAPPER;
|
||||||
|
#endif
|
||||||
|
|
||||||
return ptr_array_free (array, flags);
|
return ptr_array_free (array, flags);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user