summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2012-03-20 15:19:54 +0100
committerStephen Gallagher <sgallagh@redhat.com>2012-03-28 15:07:05 -0400
commit612231a05770a79b8ff53f91d85f5be7595ed785 (patch)
tree418f0e2cec88c6b20a84b7a94ed9c804eaff473f /src
parenta6098862048d4bb469130b9ff21be3020d6f2c54 (diff)
downloadsssd-612231a05770a79b8ff53f91d85f5be7595ed785.tar.gz
sssd-612231a05770a79b8ff53f91d85f5be7595ed785.tar.bz2
sssd-612231a05770a79b8ff53f91d85f5be7595ed785.zip
Silence Coverity warning in the autofs test tool
https://fedorahosted.org/sssd/ticket/1237
Diffstat (limited to 'src')
-rw-r--r--src/sss_client/autofs/autofs_test_client.c30
1 files changed, 22 insertions, 8 deletions
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;
}