summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakub Jelen <jjelen@redhat.com>2020-04-20 18:49:17 +0200
committerFrediano Ziglio <freddy77@gmail.com>2020-04-26 21:35:17 +0100
commite58b911d0983d6a6b196df97b517a82df866e9d5 (patch)
tree9f802294dd50fe6ae2a9f15a362869747ae060ba /src
parent9d352ecdaf8ccf446c7e1c9706cb7329b5647f9d (diff)
vcard_emul_nss: Clean up memory
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Acked-by: Frediano Ziglio <fziglio@redhat.com>
Diffstat (limited to 'src')
-rw-r--r--src/vcard_emul_nss.c38
1 files changed, 27 insertions, 11 deletions
diff --git a/src/vcard_emul_nss.c b/src/vcard_emul_nss.c
index 0a86546..a79626e 100644
--- a/src/vcard_emul_nss.c
+++ b/src/vcard_emul_nss.c
@@ -1236,7 +1236,7 @@ static VCardEmulOptions options;
args = strpbrk(args, ",)"); \
if (args == NULL || *args == 0 || *args == ')') { \
fprintf(stderr, "Error: invalid soft specification.\n"); \
- return NULL; \
+ goto fail; \
} \
(token##_length) = args - (token); \
args = strip(args+1);
@@ -1244,7 +1244,7 @@ static VCardEmulOptions options;
VCardEmulOptions *
vcard_emul_options(const char *args)
{
- int reader_count = 0;
+ int i, j, reader_count = 0;
VCardEmulOptions *opts;
/* Allow the future use of allocating the options structure on the fly */
@@ -1268,13 +1268,13 @@ vcard_emul_options(const char *args)
size_t type_params_length;
char type_str[100];
VCardEmulType type;
- int count, i;
+ int count;
VirtualReaderOptions *vreaderOpt;
args = strip(args + 5);
if (*args != '(') {
fprintf(stderr, "Error: invalid soft specification.\n");
- return NULL;
+ goto fail;
}
args = strip(args+1);
@@ -1288,14 +1288,14 @@ vcard_emul_options(const char *args)
if (type == VCARD_EMUL_NONE) {
fprintf(stderr, "Error: invalid smartcard type '%s'.\n",
type_str);
- return NULL;
+ goto fail;
}
NEXT_TOKEN(type_params)
if (*args == 0) {
fprintf(stderr, "Error: missing cert specification.\n");
- return NULL;
+ goto fail;
}
if (opts->vreader_count >= reader_count) {
@@ -1340,7 +1340,7 @@ vcard_emul_options(const char *args)
if (opts->hw_card_type == VCARD_EMUL_NONE) {
fprintf(stderr, "Error: invalid smartcard type '%s'.\n",
args);
- return NULL;
+ goto fail;
}
args = find_blank(args);
/* hw_params= */
@@ -1356,14 +1356,14 @@ vcard_emul_options(const char *args)
args = strip(args+3);
if (*args != '"') {
fprintf(stderr, "Error: you must quote the file path.\n");
- return NULL;
+ goto fail;
}
args++;
db = args;
args = strpbrk(args, "\"\n");
if (args == NULL) {
- fprintf(stderr, "Error: invalid db argument.\n");
- return NULL;
+ fprintf(stderr, "Error: invalid db argument.\n");
+ goto fail;
}
opts->nss_db = g_strndup(db, args-db);
if (*args != 0) {
@@ -1381,11 +1381,27 @@ vcard_emul_options(const char *args)
#endif
} else {
fprintf(stderr, "Error: Unknown smartcard specification.\n");
- return NULL;
+ goto fail;
}
} while (*args != 0);
return opts;
+
+fail:
+ /* Clean up what was allocated above on failure */
+ for (i = 0; i < opts->vreader_count; i++) {
+ g_free(opts->vreader[i].name);
+ g_free(opts->vreader[i].vname);
+ g_free(opts->vreader[i].type_params);
+ for (j = 0; j < opts->vreader[i].cert_count; j++) {
+ g_free(opts->vreader[i].cert_name[j]);
+ }
+ g_free(opts->vreader[i].cert_name);
+ }
+ g_free(opts->vreader);
+ g_free(opts->hw_type_params);
+ g_free(opts->nss_db);
+ return NULL;
}
unsigned char *