From 612231a05770a79b8ff53f91d85f5be7595ed785 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Tue, 20 Mar 2012 15:19:54 +0100 Subject: Silence Coverity warning in the autofs test tool https://fedorahosted.org/sssd/ticket/1237 --- src/sss_client/autofs/autofs_test_client.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'src/sss_client/autofs/autofs_test_client.c') diff --git a/src/sss_client/autofs/autofs_test_client.c b/src/sss_client/autofs/autofs_test_client.c index 386c890c..f4395ff7 100644 --- a/src/sss_client/autofs/autofs_test_client.c +++ b/src/sss_client/autofs/autofs_test_client.c @@ -41,8 +41,8 @@ int main(int argc, const char *argv[]) void *ctx; errno_t ret; const char *mapname; - char *key; - char *value; + char *key = NULL; + char *value = NULL; char *pc_key = NULL; struct poptOption long_options[] = { POPT_AUTOHELP @@ -61,9 +61,12 @@ int main(int argc, const char *argv[]) if (mapname == NULL) { poptPrintUsage(pc, stderr, 0); fprintf(stderr, "Please specify the automounter map name\n"); + poptFreeContext(pc); exit(EXIT_FAILURE); } + poptFreeContext(pc); + ret = _sss_setautomntent(mapname, &ctx); if (ret) { fprintf(stderr, "setautomntent failed [%d]: %s\n", @@ -73,21 +76,27 @@ int main(int argc, const char *argv[]) printf("setautomntent done for %s\n", mapname); if (!pc_key) { - key = NULL; - value = NULL; do { ret = _sss_getautomntent_r(&key, &value, ctx); if (ret == 0) { + if (!key || !value) { + fprintf(stderr, + "getautomntent returned success but no data?\n"); + goto end; + } + printf("key: %s\t\tvalue: %s\n", key, value); free(key); + key = NULL; free(value); + value = NULL; } } while(ret == 0); if (ret != 0 && ret != ENOENT) { fprintf(stderr, "getautomntent_r failed [%d]: %s\n", ret, strerror(ret)); - exit(EXIT_FAILURE); + goto end; } } else { ret = _sss_getautomntbyname_r(pc_key, &value, ctx); @@ -96,13 +105,20 @@ int main(int argc, const char *argv[]) } else if (ret != 0) { fprintf(stderr, "getautomntent_r failed [%d]: %s\n", ret, strerror(ret)); - exit(EXIT_FAILURE); + goto end; } else { + if (!value) { + fprintf(stderr, "_sss_getautomntbyname_r " + "returned success but no data?\n"); + goto end; + } + printf("key: %s\t\tvalue: %s\n", pc_key, value); free(value); } } +end: ret = _sss_endautomntent(&ctx); if (ret) { fprintf(stderr, "endautomntent failed [%d]: %s\n", @@ -110,7 +126,5 @@ int main(int argc, const char *argv[]) exit(EXIT_FAILURE); } printf("endautomntent done for %s\n", mapname); - - poptFreeContext(pc); return 0; } -- cgit