Browse Source

Make sure there's no file descriptor leakage in case of error

Signed-off-by: Mauro Condarelli <mc5686@mclink.it>
Acked-by: Stefano Babic <sbabic@denx.de>
pull/5/head
Mauro Condarelli 5 years ago
committed by Stefano Babic
parent
commit
9e3586a6cd
  1. 19
      src/uboot_env.c

19
src/uboot_env.c

@ -1086,6 +1086,7 @@ int libuboot_read_config(struct uboot_ctx *ctx, const char *config)
int ndev = 0; int ndev = 0;
struct uboot_flash_env *dev; struct uboot_flash_env *dev;
char *tmp; char *tmp;
int retval = 0;
if (!config) if (!config)
return -EINVAL; return -EINVAL;
@ -1118,8 +1119,10 @@ int libuboot_read_config(struct uboot_ctx *ctx, const char *config)
/* /*
* If size is set but zero, entry is wrong * If size is set but zero, entry is wrong
*/ */
if (!dev->envsize) if (!dev->envsize) {
return -EINVAL; retval = -EINVAL;
break;
}
if (!ctx->size) if (!ctx->size)
ctx->size = dev->envsize; ctx->size = dev->envsize;
@ -1129,8 +1132,10 @@ int libuboot_read_config(struct uboot_ctx *ctx, const char *config)
free(tmp); free(tmp);
} }
if (check_env_device(ctx, dev) < 0) if (check_env_device(ctx, dev) < 0) {
return -EINVAL; retval = -EINVAL;
break;
}
ndev++; ndev++;
dev++; dev++;
@ -1138,17 +1143,17 @@ int libuboot_read_config(struct uboot_ctx *ctx, const char *config)
if (ndev >= 2) { if (ndev >= 2) {
ctx->redundant = true; ctx->redundant = true;
if (check_compatible_devices(ctx) < 0) if (check_compatible_devices(ctx) < 0)
return -EINVAL; retval = -EINVAL;
break; break;
} }
} }
if (ndev == 0) if (ndev == 0)
return -EINVAL; retval = -EINVAL;
fclose(fp); fclose(fp);
free(line); free(line);
return 0; return retval;
} }
static bool libuboot_validate_flags(struct var_entry *entry, const char *value) static bool libuboot_validate_flags(struct var_entry *entry, const char *value)

Loading…
Cancel
Save