There are a few issues with the native memory allocation in share/native/sun/security/smartcardio/pcsc.c:
1)
readerState = calloc(readers, sizeof(SCARD_READERSTATE));
if (readerState == NULL) {
throwOutOfMemoryError(env, NULL);
calloc() can return NULL due to readers be zero.
In this case OOM would be confusing.
2)
for (i = 0; i < readers; i++) {
free((char *)readerState[i].szReader);
}
We can get here upon an error, so readerState[i].szReader may not be initialized.
3)
mszReaders = malloc(size);
if (mszReaders == NULL) {
throwOutOfMemoryError(env, NULL);
return NULL;
}
If size happens to be zero, we'll get a confusing OOM.
4)
tab = (char **)malloc(cnt * sizeof(char *));
if (tab == NULL) {
throwOutOfMemoryError(env, NULL);
return NULL;
}
Again, we can get NULL from malloc, if cnt == 0.