Fix FILE leak in error path.
authorclaudio <claudio@openbsd.org>
Tue, 13 Jun 2023 08:45:41 +0000 (08:45 +0000)
committerclaudio <claudio@openbsd.org>
Tue, 13 Jun 2023 08:45:41 +0000 (08:45 +0000)
If flowf is NULL then fclose(spif) must be called.
Split up the error check from if (spif == NULL || flowf == NULL) to
individual checks since that is easier to read.

Noticed by markus@, OK tb@

sbin/iked/ikev2.c

index 8c61065..dc641fa 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ikev2.c,v 1.368 2023/06/12 09:02:31 claudio Exp $     */
+/*     $OpenBSD: ikev2.c,v 1.369 2023/06/13 08:45:41 claudio Exp $     */
 
 /*
  * Copyright (c) 2019 Tobias Heider <tobias.heider@stusta.de>
@@ -6430,9 +6430,14 @@ ikev2_childsa_enable(struct iked *env, struct iked_sa *sa)
        int                      ret = -1;
 
        spif = open_memstream(&spibuf, &spisz);
+       if (spif == NULL) {
+               log_warn("%s", __func__);
+               return (ret);
+       }
        flowf = open_memstream(&flowbuf, &flowsz);
-       if (spif == NULL || flowf == NULL) {
+       if (flowf == NULL) {
                log_warn("%s", __func__);
+               fclose(spif);
                return (ret);
        }