-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 This patch looks good to me. acked. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk6wTioACgkQrlYvE4MpobOnyACeIVzY1VzxGuZhcnSp7nAgQolV PPYAoNtFKk2gne6tj2B04gv2/Vp9Ehof =MfbY -----END PGP SIGNATURE-----
>From 91aebddc6e0af2d3f39ea0eec637cb4189aa5f78 Mon Sep 17 00:00:00 2001 From: Eric Paris <eparis@xxxxxxxxxx> Date: Mon, 3 Oct 2011 15:44:14 -0400 Subject: [PATCH 45/63] libselinux: label: cosmetic cleanups Return early to save an indent. Clean up all memory on ENOMEM conditions. Use '\0' instead of 0 for nul terminiator. Style changes to make Eric happy. Signed-off-by: Eric Paris <eparis@xxxxxxxxxx> --- libselinux/src/label.c | 86 ++++++++++++++++++++++++++---------------------- 1 files changed, 47 insertions(+), 39 deletions(-) diff --git a/libselinux/src/label.c b/libselinux/src/label.c index 7d71e72..f1c9a25 100644 --- a/libselinux/src/label.c +++ b/libselinux/src/label.c @@ -62,50 +62,58 @@ struct selabel_sub *selabel_subs_init(const char *path,struct selabel_sub *list) FILE *cfg = fopen(path, "r"); struct selabel_sub *sub; - if (cfg) { - while (fgets_unlocked(buf, sizeof(buf) - 1, cfg)) { - char *ptr = NULL; - char *src = buf; - char *dst = NULL; + if (!cfg) + return list; - while (*src && isspace(*src)) - src++; - if (src[0] == '#') continue; - ptr = src; - while (*ptr && ! isspace(*ptr)) - ptr++; - *ptr++ = 0; - if (! *src) continue; + while (fgets_unlocked(buf, sizeof(buf) - 1, cfg)) { + char *ptr = NULL; + char *src = buf; + char *dst = NULL; - dst = ptr; - while (*dst && isspace(*dst)) - dst++; - ptr=dst; - while (*ptr && ! isspace(*ptr)) - ptr++; - *ptr=0; - if (! *dst) continue; + while (*src && isspace(*src)) + src++; + if (src[0] == '#') continue; + ptr = src; + while (*ptr && ! isspace(*ptr)) + ptr++; + *ptr++ = '\0'; + if (! *src) continue; - sub = malloc(sizeof(struct selabel_sub)); - if (! sub) return list; - sub->src=strdup(src); - if (! sub->src) { - free(sub); - return list; - } - sub->dst=strdup(dst); - if (! sub->dst) { - free(sub->src); - free(sub); - return list; - } - sub->slen = strlen(src); - sub->next = list; - list = sub; - } - fclose(cfg); + dst = ptr; + while (*dst && isspace(*dst)) + dst++; + ptr=dst; + while (*ptr && ! isspace(*ptr)) + ptr++; + *ptr='\0'; + if (! *dst) + continue; + + sub = malloc(sizeof(*sub)); + if (! sub) + goto err; + memset(sub, 0, sizeof(*sub)); + + sub->src=strdup(src); + if (! sub->src) + goto err; + + sub->dst=strdup(dst); + if (! sub->dst) + goto err; + + sub->slen = strlen(src); + sub->next = list; + list = sub; } +out: + fclose(cfg); return list; +err: + if (sub) + free(sub->src); + free(sub); + goto out; } /* -- 1.7.7