env: fix memory leak in fw_env routines
fw_env_open allocates buffers to store the environment, but these
buffers are never freed. This becomes quite nasty using the fw_ tools as
library, because each access to the environment (even just reading a
variable) generates a memory leak equal to the size of the environment.
Fix this renaming fw_env_close() as fw_env_flush(), because the function
really flushes the environment from RAM to storage, and add a
fw_env_close function to free the allocated resources.
Signed-off-by: Stefano Babic <sbabic@denx.de>
diff --git a/tools/env/fw_env.h b/tools/env/fw_env.h
index cf346b3..04bb646 100644
--- a/tools/env/fw_env.h
+++ b/tools/env/fw_env.h
@@ -53,7 +53,7 @@
* @opts: how to retrieve environment from flash, defaults are used if NULL
*
* Description:
- * Uses fw_env_open, fw_env_write, fw_env_close
+ * Uses fw_env_open, fw_env_write, fw_env_flush
*
* Return:
* 0 on success, -1 on failure (modifies errno)
@@ -70,7 +70,7 @@
* @opts: encryption key, configuration file, defaults are used if NULL
*
* Description:
- * Uses fw_env_open, fw_env_write, fw_env_close
+ * Uses fw_env_open, fw_env_write, fw_env_flush
*
* Return:
* 0 success, -1 on failure (modifies errno)
@@ -138,15 +138,26 @@
int fw_env_write(char *name, char *value);
/**
- * fw_env_close - write the environment from RAM cache back to flash
+ * fw_env_flush - write the environment from RAM cache back to flash
*
* @opts: encryption key, configuration file, defaults are used if NULL
*
* Return:
* 0 on success, -1 on failure (modifies errno)
*/
+int fw_env_flush(struct env_opts *opts);
+
+/**
+ * fw_env_close - free allocated structure and close env
+ *
+ * @opts: encryption key, configuration file, defaults are used if NULL
+ *
+ * Return:
+ * 0 on success, -1 on failure (modifies errno)
+ */
int fw_env_close(struct env_opts *opts);
+
/**
* fw_env_version - return the current version of the library
*