1
1
/*
2
- * Copyright (c) 1997, 2014 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 1997, 2022 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -454,6 +454,7 @@ int awt_parseColorModel (JNIEnv *env, jobject jcmodel, int imageType,
454
454
455
455
int i ;
456
456
static jobject s_jdefCM = NULL ;
457
+ cmP -> nBits = NULL ;
457
458
458
459
if (JNU_IsNull (env , jcmodel )) {
459
460
JNU_ThrowNullPointerException (env , "null ColorModel object" );
@@ -485,7 +486,6 @@ int awt_parseColorModel (JNIEnv *env, jobject jcmodel, int imageType,
485
486
return -1 ;
486
487
}
487
488
488
- cmP -> nBits = NULL ;
489
489
if (SAFE_TO_ALLOC_2 (cmP -> numComponents , sizeof (jint ))) {
490
490
cmP -> nBits = (jint * )malloc (cmP -> numComponents * sizeof (jint ));
491
491
}
@@ -508,7 +508,9 @@ int awt_parseColorModel (JNIEnv *env, jobject jcmodel, int imageType,
508
508
cmP -> csType = (* env )-> GetIntField (env , cmP -> jcmodel , g_CMcsTypeID );
509
509
510
510
cmP -> cmType = getColorModelType (env , jcmodel );
511
- JNU_CHECK_EXCEPTION_RETURN (env , -1 );
511
+ if ((* env )-> ExceptionCheck (env )) {
512
+ goto cleanup ;
513
+ }
512
514
513
515
cmP -> isDefaultCM = FALSE;
514
516
cmP -> isDefaultCompatCM = FALSE;
@@ -530,14 +532,21 @@ int awt_parseColorModel (JNIEnv *env, jobject jcmodel, int imageType,
530
532
if (s_jdefCM == NULL ) {
531
533
jobject defCM ;
532
534
jclass jcm = (* env )-> FindClass (env , "java/awt/image/ColorModel" );
533
- CHECK_NULL_RETURN (jcm , -1 );
535
+ if (jcm == NULL ) {
536
+ goto cleanup ;
537
+ }
534
538
defCM = (* env )-> CallStaticObjectMethod (env , jcm ,
535
539
g_CMgetRGBdefaultMID , NULL );
540
+ if ((* env )-> ExceptionCheck (env )) {
541
+ (* env )-> ExceptionClear (env );
542
+ JNU_ThrowNullPointerException (env , "Unable to find default CM" );
543
+ goto cleanup ;
544
+ }
536
545
s_jdefCM = (* env )-> NewGlobalRef (env , defCM );
537
546
if (defCM == NULL || s_jdefCM == NULL ) {
538
547
(* env )-> ExceptionClear (env );
539
548
JNU_ThrowNullPointerException (env , "Unable to find default CM" );
540
- return -1 ;
549
+ goto cleanup ;
541
550
}
542
551
}
543
552
cmP -> isDefaultCM = ((* env )-> IsSameObject (env , s_jdefCM , jcmodel ));
@@ -549,12 +558,12 @@ int awt_parseColorModel (JNIEnv *env, jobject jcmodel, int imageType,
549
558
if (cmP -> csType != java_awt_color_ColorSpace_TYPE_RGB ||
550
559
!cmP -> is_sRGB )
551
560
{
552
- return -1 ;
561
+ goto cleanup ;
553
562
}
554
563
555
564
for (i = 0 ; i < cmP -> numComponents ; i ++ ) {
556
565
if (cmP -> nBits [i ] != 8 ) {
557
- return -1 ;
566
+ goto cleanup ;
558
567
}
559
568
}
560
569
}
@@ -572,7 +581,7 @@ int awt_parseColorModel (JNIEnv *env, jobject jcmodel, int imageType,
572
581
cmP -> jrgb ,
573
582
NULL );
574
583
if (rgb == NULL ) {
575
- return -1 ;
584
+ goto cleanup ;
576
585
}
577
586
for (i = 0 ; i < cmP -> mapSize ; i ++ ) {
578
587
if ((rgb [i ]& 0xff000000 ) == 0 ) {
@@ -590,6 +599,10 @@ int awt_parseColorModel (JNIEnv *env, jobject jcmodel, int imageType,
590
599
}
591
600
592
601
return 1 ;
602
+
603
+ cleanup :
604
+ free (cmP -> nBits );
605
+ return -1 ;
593
606
}
594
607
595
608
void awt_freeParsedRaster (RasterS_t * rasterP , int freeRasterP ) {
0 commit comments