diff options
author | Gianni Tedesco <gianni.tedesco@citrix.com> | 2010-09-09 17:56:11 +0100 |
---|---|---|
committer | Gianni Tedesco <gianni.tedesco@citrix.com> | 2010-09-09 17:56:11 +0100 |
commit | 73de3694a9c11900aa6e04593b7b90a7548d11da (patch) | |
tree | af376b7be456efe84ac994580f497841d513ba21 /tools/libxl/libxlu_cfg.c | |
parent | ec6adc366137da966bc97691bc50ceb1fe57298c (diff) | |
download | xen-73de3694a9c11900aa6e04593b7b90a7548d11da.tar.gz xen-73de3694a9c11900aa6e04593b7b90a7548d11da.tar.bz2 xen-73de3694a9c11900aa6e04593b7b90a7548d11da.zip |
libxl, xl: don't free string literals in config structure
The function init_dm_info() is initialising some strings from literals.
This is bad juju because when the destructor is called we cannot know if
the string literal was overridden with a strdup()'d value. Therefore
strdup values in the initialiser then introduce and use the function
libxlu_cfg_replace_string() which free's whatever is set before
strdupping the new value on top of it. The rule for the new call should
be clear due to const vs. non-const arguments - changing the behaviour
of libxlu_cfg_get_string() would cause more complexity than it saves.
[ fixed up for stray ! sign -iwj ]
Signed-off-by: Gianni Tedesco <gianni.tedesco@citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Diffstat (limited to 'tools/libxl/libxlu_cfg.c')
-rw-r--r-- | tools/libxl/libxlu_cfg.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/tools/libxl/libxlu_cfg.c b/tools/libxl/libxlu_cfg.c index 09a7c71eda..07e65e1043 100644 --- a/tools/libxl/libxlu_cfg.c +++ b/tools/libxl/libxlu_cfg.c @@ -151,7 +151,18 @@ int xlu_cfg_get_string(const XLU_Config *cfg, const char *n, *value_r= set->values[0]; return 0; } - + +int xlu_cfg_replace_string(const XLU_Config *cfg, const char *n, + char **value_r) { + XLU_ConfigSetting *set; + int e; + + e= find_atom(cfg,n,&set); if (e) return e; + free(*value_r); + *value_r= strdup(set->values[0]); + return 0; +} + int xlu_cfg_get_long(const XLU_Config *cfg, const char *n, long *value_r) { long l; |