summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1d4f883)
raw | patch | inline | side by side (parent: 1d4f883)
author | Sebastian Harl <sh@tokkee.org> | |
Fri, 30 Jan 2015 11:01:48 +0000 (12:01 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Fri, 30 Jan 2015 11:01:48 +0000 (12:01 +0100) |
This simplifies cleanup.
src/tools/sysdb/input.c | patch | blob | history | |
src/tools/sysdb/input.h | patch | blob | history | |
src/tools/sysdb/main.c | patch | blob | history |
index a1e7b714b689a85e946587624948a6d237eef78c..0b0dbf719c20fee8acbd29218530d4d51838430c 100644 (file)
--- a/src/tools/sysdb/input.c
+++ b/src/tools/sysdb/input.c
return 0;
} /* sdb_input_init */
+void
+sdb_input_reset(sdb_input_t *input)
+{
+ sdb_input_t reset = SDB_INPUT_INIT;
+
+ if (! input)
+ return;
+
+ if (input->client)
+ sdb_client_destroy(input->client);
+ if (input->user)
+ free(input->user);
+ if (input->input)
+ sdb_strbuf_destroy(input->input);
+
+ *input = reset;
+} /* sdb_input_reset */
+
int
sdb_input_mainloop(void)
{
index ba2b32d8d3553dad528bfda657d7f18f79b20234..6002c1f3d5464f992c01bae48aa38b55819a0eae 100644 (file)
--- a/src/tools/sysdb/input.h
+++ b/src/tools/sysdb/input.h
int
sdb_input_init(sdb_input_t *input);
+/*
+ * sdb_input_reset:
+ * Reset the input handler and free all dynamically allocated memory. The
+ * input handler object itself will not be freed.
+ */
+void
+sdb_input_reset(sdb_input_t *input);
+
/*
* sdb_input_mainloop:
* Wait for and handle all user and server input until end-of-file is read
diff --git a/src/tools/sysdb/main.c b/src/tools/sysdb/main.c
index b22e11f0f89da462596783a000ffdcb2d70835fa..91a67232afaeda429cfd78689061ea87781697c5 100644 (file)
--- a/src/tools/sysdb/main.c
+++ b/src/tools/sysdb/main.c
input.client = sdb_client_create(host);
if (! input.client) {
sdb_log(SDB_LOG_ERR, "Failed to create client object");
- free(input.user);
+ sdb_input_reset(&input);
exit(1);
}
if (sdb_client_connect(input.client, input.user)) {
sdb_log(SDB_LOG_ERR, "Failed to connect to SysDBd");
- sdb_client_destroy(input.client);
- free(input.user);
+ sdb_input_reset(&input);
exit(1);
}
if (commands) {
int status = execute_commands(input.client, commands);
sdb_llist_destroy(commands);
- sdb_client_destroy(input.client);
- free(input.user);
+ sdb_input_reset(&input);
if ((status != SDB_CONNECTION_OK) && (status != SDB_CONNECTION_DATA))
exit(1);
exit(0);
hist_file, sdb_strerror(errno, errbuf, sizeof(errbuf)));
}
}
- free(input.user);
input.input = sdb_strbuf_create(2048);
sdb_input_init(&input);
}
}
- sdb_client_destroy(input.client);
- sdb_strbuf_destroy(input.input);
+ sdb_input_reset(&input);
ERR_free_strings();
return 0;