Add Increment and Decrement count positive check in ReferenceCountUtil (#11523)
Motivation: We should have guards in place to check increment or decrement count in `ReferenceCountUtil`. Increment and Decrement counts must be a positive integer. Modification: Added `ObjectUtil#checkPositive` checks. Result: Prevent release due to invalid count.
This commit is contained in:
parent
b6da6f5828
commit
82418dafec
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package io.netty.util;
|
||||
|
||||
import io.netty.util.internal.ObjectUtil;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import io.netty.util.internal.logging.InternalLogger;
|
||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||
@ -48,6 +49,7 @@ public final class ReferenceCountUtil {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T retain(T msg, int increment) {
|
||||
ObjectUtil.checkPositive(increment, "increment");
|
||||
if (msg instanceof ReferenceCounted) {
|
||||
return (T) ((ReferenceCounted) msg).retain(increment);
|
||||
}
|
||||
@ -95,6 +97,7 @@ public final class ReferenceCountUtil {
|
||||
* If the specified message doesn't implement {@link ReferenceCounted}, this method does nothing.
|
||||
*/
|
||||
public static boolean release(Object msg, int decrement) {
|
||||
ObjectUtil.checkPositive(decrement, "decrement");
|
||||
if (msg instanceof ReferenceCounted) {
|
||||
return ((ReferenceCounted) msg).release(decrement);
|
||||
}
|
||||
@ -125,6 +128,7 @@ public final class ReferenceCountUtil {
|
||||
*/
|
||||
public static void safeRelease(Object msg, int decrement) {
|
||||
try {
|
||||
ObjectUtil.checkPositive(decrement, "decrement");
|
||||
release(msg, decrement);
|
||||
} catch (Throwable t) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
@ -154,6 +158,7 @@ public final class ReferenceCountUtil {
|
||||
*/
|
||||
@Deprecated
|
||||
public static <T> T releaseLater(T msg, int decrement) {
|
||||
ObjectUtil.checkPositive(decrement, "decrement");
|
||||
if (msg instanceof ReferenceCounted) {
|
||||
ThreadDeathWatcher.watch(Thread.currentThread(), new ReleasingTask((ReferenceCounted) msg, decrement));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user