vcard_emul_alloc_arrays(unsigned char ***certsp, int **cert_lenp,
VCardKey ***keysp, int cert_count)
{
- *certsp = (unsigned char **)g_malloc(sizeof(unsigned char *)*cert_count);
- *cert_lenp = (int *)g_malloc(sizeof(int)*cert_count);
- *keysp = (VCardKey **)g_malloc(sizeof(VCardKey *)*cert_count);
+ *certsp = g_new(unsigned char *, cert_count);
+ *cert_lenp = g_new(int, cert_count);
+ *keysp = g_new(VCardKey *, cert_count);
}
/*
{
VCardKey *key;
- key = (VCardKey *)g_malloc(sizeof(VCardKey));
+ key = g_new(VCardKey, 1);
key->slot = PK11_ReferenceSlot(slot);
key->cert = CERT_DupCertificate(cert);
/* NOTE: if we aren't logged into the token, this could return NULL */
}
}
if ((i < buffer_size) && (buffer[i] == 0)) {
- /* yes, we have a properly formated PKCS #1 signature */
+ /* yes, we have a properly formatted PKCS #1 signature */
/*
* NOTE: even if we accidentally got an encrypt buffer, which
- * through shear luck started with 00, 01, ff, 00, it won't matter
+ * through sheer luck started with 00, 01, ff, 00, it won't matter
* because the resulting Sign operation will effectively decrypt
* the real buffer.
*/
vcard_emul_login(VCard *card, unsigned char *pin, int pin_len)
{
PK11SlotInfo *slot;
- unsigned char *pin_string = NULL;
+ unsigned char *pin_string;
int i;
SECStatus rv;
vcard_emul_find_vreader_from_slot(PK11SlotInfo *slot)
{
VReaderList *reader_list = vreader_get_reader_list();
- VReaderListEntry *current_entry = NULL;
+ VReaderListEntry *current_entry;
if (reader_list == NULL) {
return NULL;
VReader *reader = vreader_list_get_reader(current_entry);
VReaderEmul *reader_emul = vreader_get_private(reader);
if (reader_emul->slot == slot) {
+ vreader_list_delete(reader_list);
return reader;
}
vreader_free(reader);
}
+ vreader_list_delete(reader_list);
return NULL;
}
{
VReaderEmul *new_reader_emul;
- new_reader_emul = (VReaderEmul *)g_malloc(sizeof(VReaderEmul));
+ new_reader_emul = g_new(VReaderEmul, 1);
new_reader_emul->slot = PK11_ReferenceSlot(slot);
new_reader_emul->default_type = type;
if (vreader_emul->slot) {
PK11_FreeSlot(vreader_emul->slot);
}
- if (vreader_emul->type_params) {
- g_free(vreader_emul->type_params);
- }
+ g_free(vreader_emul->type_params);
g_free(vreader_emul);
}
cert_count++;
}
- if (cert_count == 0) {
- PK11_DestroyGenericObjects(firstObj);
- return NULL;
- }
-
/* allocate the arrays */
vcard_emul_alloc_arrays(&certs, &cert_len, &keys, cert_count);
vcard_emul_replay_insertion_events(void)
{
VReaderListEntry *current_entry;
- VReaderListEntry *next_entry = NULL;
+ VReaderListEntry *next_entry;
VReaderList *list = vreader_get_reader_list();
for (current_entry = vreader_list_get_first(list); current_entry;
next_entry = vreader_list_get_next(current_entry);
vreader_queue_card_event(vreader);
}
+
+ vreader_list_delete(list);
}
/*
char type_str[100];
VCardEmulType type;
int count, i;
- VirtualReaderOptions *vreaderOpt = NULL;
+ VirtualReaderOptions *vreaderOpt;
args = strip(args + 5);
if (*args != '(') {
NEXT_TOKEN(vname)
NEXT_TOKEN(type_params)
type_params_length = MIN(type_params_length, sizeof(type_str)-1);
- pstrcpy(type_str, type_params_length, type_params);
+ memcpy(type_str, type_params, type_params_length);
+ type_str[type_params_length] = '\0';
type = vcard_emul_type_from_string(type_str);
NEXT_TOKEN(type_params)
if (opts->vreader_count >= reader_count) {
reader_count += READER_STEP;
- vreaderOpt = realloc(opts->vreader,
- reader_count * sizeof(*vreaderOpt));
- if (vreaderOpt == NULL) {
- return opts; /* we're done */
- }
+ opts->vreader = g_renew(VirtualReaderOptions, opts->vreader,
+ reader_count);
}
- opts->vreader = vreaderOpt;
- vreaderOpt = &vreaderOpt[opts->vreader_count];
+ vreaderOpt = &opts->vreader[opts->vreader_count];
vreaderOpt->name = g_strndup(name, name_length);
vreaderOpt->vname = g_strndup(vname, vname_length);
vreaderOpt->card_type = type;
g_strndup(type_params, type_params_length);
count = count_tokens(args, ',', ')') + 1;
vreaderOpt->cert_count = count;
- vreaderOpt->cert_name = (char **)g_malloc(count*sizeof(char *));
+ vreaderOpt->cert_name = g_new(char *, count);
for (i = 0; i < count; i++) {
const char *cert = args;
args = strpbrk(args, ",)");