From d2b525e7650e9f81dfaa14656866318c45d0b765 Mon Sep 17 00:00:00 2001 From: George Burgess IV <gbiv@google.com> Date: Wed, 31 Oct 2018 18:08:21 -0700 Subject: [PATCH] Silence a static analyzer warning Our static analyzer is unhappy with this code, and thinks it has a memory leak: device/generic/opengl-transport/host/libs/virglrenderer/AVDVirglRenderer.cpp:343:38: warning: Potential leak of memory pointed to by 'config' [clang-analyzer-cplusplus.NewDeleteLeaks] While this immediately seems true, the constructor for `config` will stash a pointer to `config` in a static vector, which presumably is meant to manage the lifetime of our newly-allocated `config`. As noted in the comments, the analyzer can generally reason about that, but it gives up trying to figure out what the constructor is doing before we reach the vector's push_back. Just put a NOLINT here to make it be quiet. Bug: None Test: Ran the analyzer. It's no longer angry. Change-Id: Ida0118ef8b9ca0cd40cdd5e76489ab14cb86ea23 --- host/libs/virglrenderer/AVDVirglRenderer.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/host/libs/virglrenderer/AVDVirglRenderer.cpp b/host/libs/virglrenderer/AVDVirglRenderer.cpp index 2be15d5a1..788c3eddd 100644 --- a/host/libs/virglrenderer/AVDVirglRenderer.cpp +++ b/host/libs/virglrenderer/AVDVirglRenderer.cpp @@ -340,6 +340,14 @@ int virgl_renderer_init(void* cookie, int flags, virgl_renderer_callbacks* cb) { g_dpy = EGL_NO_DISPLAY; return ENOENT; } + + // Our static analyzer sees the `new`ing of `config` below without any sort + // of attempt to free it, and warns about it. Normally, it would catch that + // we're pushing it into a vector in the constructor, but it hits an + // internal evaluation limit when trying to evaluate the loop inside of the + // ctor. So, it never gets to see that we escape our newly-allocated + // `config` instance. Silence the warning, since it's incorrect. + // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) for (EGLint c = 0; c < nConfigs; c++) { EGLint configId; if (!s_egl.eglGetConfigAttrib(g_dpy, configs[c], EGL_CONFIG_ID, &configId)) { -- GitLab