]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: buffer_free() - Check for buf==NULL before using container_of()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 4 Oct 2021 11:42:54 +0000 (14:42 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Tue, 5 Oct 2021 09:57:30 +0000 (09:57 +0000)
Helps with static analyzer complaints.

src/lib/buffer.c

index 55f230b321e3b35279ccb535162db7036f78a147..f6f3a0f9eca6a25ca5d4f048191574f93efb9a30 100644 (file)
@@ -184,10 +184,9 @@ buffer_t *buffer_create_dynamic_max(pool_t pool, size_t init_size,
 
 void buffer_free(buffer_t **_buf)
 {
-       struct real_buffer *buf = container_of(*_buf, struct real_buffer, buf);
-
-       if (buf == NULL)
+       if (*_buf == NULL)
                return;
+       struct real_buffer *buf = container_of(*_buf, struct real_buffer, buf);
 
        *_buf = NULL;
        if (buf->alloced)