nwrap: Correctly handle realloc() in nwrap_module_init()
authorAndreas Schneider <asn@samba.org>
Thu, 2 Apr 2020 07:51:22 +0000 (09:51 +0200)
committerAndreas Schneider <asn@samba.org>
Thu, 2 Apr 2020 09:28:52 +0000 (11:28 +0200)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Samuel Cabrero <scabrero@suse.de>
src/nss_wrapper.c

index a192f0e21990fdb864eed32c60f022ef74155bfe..17c87321d4d5dbd9c7547a29e5ab5872afacd0be 100644 (file)
@@ -1796,14 +1796,15 @@ static bool nwrap_module_init(const char *name,
                              size_t *num_backends,
                              struct nwrap_backend **backends)
 {
-       struct nwrap_backend *b;
+       struct nwrap_backend *b = NULL;
+       size_t n = *num_backends + 1;
 
-       *backends = (struct nwrap_backend *)realloc(*backends,
-               sizeof(struct nwrap_backend) * ((*num_backends) + 1));
-       if (!*backends) {
+       b = realloc(*backends, sizeof(struct nwrap_backend) * n);
+       if (b == NULL) {
                NWRAP_LOG(NWRAP_LOG_ERROR, "Out of memory");
                return false;
        }
+       *backends = b;
 
        b = &((*backends)[*num_backends]);
 
@@ -1821,7 +1822,7 @@ static bool nwrap_module_init(const char *name,
                }
        }
 
-       (*num_backends)++;
+       *num_backends = n;
 
        return true;
 }