[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen master] libxl: make some _dispose functions idempotent and tolerate NULL
commit 1ea68f1a82ef94b3cc644fa70307c5151f356baf Author: Wei Liu <wei.liu2@xxxxxxxxxx> AuthorDate: Wed Feb 25 14:56:02 2015 +0000 Commit: Ian Campbell <ian.campbell@xxxxxxxxxx> CommitDate: Mon Mar 2 17:05:35 2015 +0000 libxl: make some _dispose functions idempotent and tolerate NULL These functions are not generated, so we need to do it by hand. Functions list: libxl_bitmap_dispose libxl_string_list_dispose libxl_key_value_list_dipose libxl_cpuid_dispose Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx> Cc: Ian Campbell <ian.campbell@xxxxxxxxxx> Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx> --- tools/libxl/libxl.c | 11 +++++++++-- tools/libxl/libxl_cpuid.c | 5 ++++- tools/libxl/libxl_utils.c | 5 +++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index a085621..088786e 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -214,9 +214,12 @@ void libxl_string_list_dispose(libxl_string_list *psl) if (!sl) return; - for (i = 0; sl[i] != NULL; i++) + for (i = 0; sl[i] != NULL; i++) { free(sl[i]); + sl[i] = NULL; + } free(sl); + *psl = NULL; } void libxl_string_list_copy(libxl_ctx *ctx, @@ -276,10 +279,14 @@ void libxl_key_value_list_dispose(libxl_key_value_list *pkvl) for (i = 0; kvl[i] != NULL; i += 2) { free(kvl[i]); - if (kvl[i + 1]) + kvl[i] = NULL; + if (kvl[i + 1]) { free(kvl[i + 1]); + kvl[i+1] = NULL; + } } free(kvl); + *pkvl = NULL; } void libxl_key_value_list_copy(libxl_ctx *ctx, diff --git a/tools/libxl/libxl_cpuid.c b/tools/libxl/libxl_cpuid.c index 7cfa6b7..b0bdc9d 100644 --- a/tools/libxl/libxl_cpuid.c +++ b/tools/libxl/libxl_cpuid.c @@ -28,10 +28,13 @@ void libxl_cpuid_dispose(libxl_cpuid_policy_list *p_cpuid_list) return; for (i = 0; cpuid_list[i].input[0] != XEN_CPUID_INPUT_UNUSED; i++) { for (j = 0; j < 4; j++) - if (cpuid_list[i].policy[j] != NULL) + if (cpuid_list[i].policy[j] != NULL) { free(cpuid_list[i].policy[j]); + cpuid_list[i].policy[j] = NULL; + } } free(cpuid_list); + *p_cpuid_list = NULL; return; } diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c index 7095b58..9053b27 100644 --- a/tools/libxl/libxl_utils.c +++ b/tools/libxl/libxl_utils.c @@ -604,7 +604,12 @@ void libxl_bitmap_init(libxl_bitmap *map) void libxl_bitmap_dispose(libxl_bitmap *map) { + if (!map) + return; + free(map->map); + map->map = NULL; + map->size = 0; } void libxl_bitmap_copy(libxl_ctx *ctx, libxl_bitmap *dptr, -- generated by git-patchbot for /home/xen/git/xen.git#master _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |