Skip to content

Commit

Permalink
Fix coverity warning over mem leak in smartcard code
Browse files Browse the repository at this point in the history
  • Loading branch information
matt335672 committed Jan 24, 2025
1 parent b56b2da commit 201cdc1
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions sesman/chansrv/smartcard_pcsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ scard_function_list_readers_return(void *user_data,
struct trans *con;
struct pcsc_list_readers *pcscListReaders;
char *msz_readers = NULL;
int rv;

LOG_DEVEL(LOG_LEVEL_DEBUG, "scard_function_list_readers_return:");
LOG_DEVEL(LOG_LEVEL_DEBUG, " status 0x%8.8x", status);
Expand Down Expand Up @@ -788,37 +789,41 @@ scard_function_list_readers_return(void *user_data,
out_s = trans_get_out_s(con, 8192);
if (out_s == NULL)
{
return 1;
rv = 1;
}
s_push_layer(out_s, iso_hdr, 8);
out_uint32_le(out_s, llen);
out_uint32_le(out_s, readers);
else
{
const char *p = msz_readers;
for (index = 0; index < readers; index++)
s_push_layer(out_s, iso_hdr, 8);
out_uint32_le(out_s, llen);
out_uint32_le(out_s, readers);
{
unsigned int slen = strlen(p);
if (slen < 100)
{
out_uint8a(out_s, p, slen);
out_uint8s(out_s, 100 - slen);
}
else
const char *p = msz_readers;
for (index = 0; index < readers; index++)
{
out_uint8a(out_s, p, 99);
out_uint8s(out_s, 1);
unsigned int slen = strlen(p);
if (slen < 100)
{
out_uint8a(out_s, p, slen);
out_uint8s(out_s, 100 - slen);
}
else
{
out_uint8a(out_s, p, 99);
out_uint8s(out_s, 1);
}
p += (slen + 1);
}
p += (slen + 1);
}
out_uint32_le(out_s, status); /* SCARD_S_SUCCESS status */
s_mark_end(out_s);
bytes = (int) (out_s->end - out_s->data);
s_pop_layer(out_s, iso_hdr);
out_uint32_le(out_s, bytes - 8);
out_uint32_le(out_s, 0x03); /* SCARD_LIST_READERS 0x03 */
rv = trans_force_write(con);
}
free(msz_readers);
out_uint32_le(out_s, status); /* SCARD_S_SUCCESS status */
s_mark_end(out_s);
bytes = (int) (out_s->end - out_s->data);
s_pop_layer(out_s, iso_hdr);
out_uint32_le(out_s, bytes - 8);
out_uint32_le(out_s, 0x03); /* SCARD_LIST_READERS 0x03 */
return trans_force_write(con);
return rv;
}

/*****************************************************************************/
Expand Down

0 comments on commit 201cdc1

Please sign in to comment.