summaryrefslogtreecommitdiff
path: root/jurt
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2018-11-03 14:57:29 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2018-11-03 15:20:43 +0100
commit882c7f4a1feb81ed74b4243d884ecc3a954e3bed (patch)
treee5565603a8dd2dbb87aafe9ccd665826f83c1809 /jurt
parent2a3f5d11522cd69f0ce221cde3a63b7e85e94b53 (diff)
tdf#120703 PVS: V547 Expression is always true
This fixes possible leaks from missed pipe releases Change-Id: Ic3cdbd46e0eadc503e5711fe447d14bd5f0f7273 Reviewed-on: https://gerrit.libreoffice.org/62804 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'jurt')
-rw-r--r--jurt/source/pipe/com_sun_star_lib_connections_pipe_PipeConnection.c87
1 files changed, 43 insertions, 44 deletions
diff --git a/jurt/source/pipe/com_sun_star_lib_connections_pipe_PipeConnection.c b/jurt/source/pipe/com_sun_star_lib_connections_pipe_PipeConnection.c
index 5259bbcd5474..9b7806b8a07a 100644
--- a/jurt/source/pipe/com_sun_star_lib_connections_pipe_PipeConnection.c
+++ b/jurt/source/pipe/com_sun_star_lib_connections_pipe_PipeConnection.c
@@ -258,34 +258,36 @@ JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_closeJNI
{
enum {
START = 0,
- INMONITOR
+ INMONITOR,
+ GOTPIPE,
};
- short state = START;
- oslPipe npipe; /* native pipe */
- jclass tclass; /* this class */
- jfieldID fid; /* a field identifier */
+ short state = START;
+ oslPipe npipe = NULL; /* native pipe */
+ jclass tclass; /* this class */
+ jfieldID fid; /* a field identifier */
if ((*env)->MonitorEnter(env, obj_this) != 0)
{
ThrowException(env,
"java/lang/RuntimeException",
"native pipe cannot synchronize on the object");
- goto error;
+ goto cleanup;
}
state = INMONITOR;
/* check connection state */
npipe = getPipe(env, obj_this);
if ((*env)->ExceptionOccurred(env) != NULL)
- goto error;
+ goto cleanup;
if (npipe == NULL)
{
ThrowException(env,
"com/sun/star/io/IOException",
"native pipe is not connected");
- goto error;
+ goto cleanup;
}
+ state = GOTPIPE;
/* remove the reference to the pipe */
tclass = (*env)->GetObjectClass(env, obj_this);
@@ -294,7 +296,7 @@ JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_closeJNI
ThrowException(env,
"java/lang/RuntimeException",
"native pipe cannot find class");
- goto error;
+ goto cleanup;
}
fid = (*env)->GetFieldID(env, tclass, "_nPipeHandle", "J");
@@ -303,24 +305,24 @@ JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_closeJNI
ThrowException(env,
"java/lang/RuntimeException",
"native pipe cannot find field");
- goto error;
+ goto cleanup;
}
(*env)->SetLongField(env, obj_this, fid, (jlong)0);
- /* release the pipe */
- osl_closePipe(npipe);
- osl_releasePipe(npipe);
-
/* done */
- (*env)->MonitorExit(env, obj_this);
- return;
- error:
+ cleanup:
switch (state)
{
+ case GOTPIPE:
+ /* release the pipe */
+ osl_closePipe(npipe);
+ osl_releasePipe(npipe);
+ /* fall-through */
case INMONITOR:
(*env)->MonitorExit(env, obj_this);
+ /* fall-through */
case START:
default:
break;
@@ -350,10 +352,11 @@ JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_readJNI
};
short state = START;
- oslPipe npipe; /* native pipe */
+ oslPipe npipe = NULL; /* native pipe */
void * nbuff = NULL; /* native read buffer */
jbyteArray bytes; /* java read buffer */
jint nread; /* number of bytes has been read */
+ jint nreturn = -1; /* actual return value */
/* enter monitor */
if ((*env)->MonitorEnter(env, obj_this) != 0)
@@ -361,20 +364,20 @@ JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_readJNI
ThrowException(env,
"java/lang/RuntimeException",
"native pipe cannot synchronize on the object");
- goto error;
+ goto cleanup;
}
state = INMONITOR;
/* check connection state */
npipe = getPipe(env, obj_this);
if ((*env)->ExceptionOccurred(env) != NULL)
- goto error;
+ goto cleanup;
if (npipe == NULL)
{
ThrowException(env,
"com/sun/star/io/IOException",
"native pipe is not connected");
- goto error;
+ goto cleanup;
}
/* acquire pipe */
@@ -387,7 +390,7 @@ JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_readJNI
ThrowException(env,
"java/lang/RuntimeException",
"native pipe out of memory");
- goto error;
+ goto cleanup;
}
state = GOTBUFFER;
@@ -404,7 +407,7 @@ JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_readJNI
ThrowException(env,
"java/lang/RuntimeException",
"native pipe cannot synchronize on the object");
- goto error;
+ goto cleanup;
}
/* copy buffer */
@@ -416,7 +419,7 @@ JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_readJNI
ThrowException(env,
"java/lang/RuntimeException",
"native pipe out of memory");
- goto error;
+ goto cleanup;
}
/* save the data */
@@ -426,28 +429,26 @@ JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_readJNI
}
/* done */
- free(nbuff);
- if ( state >= ACQUIRED )
- osl_releasePipe( npipe );
-
- /* exit monitor */
- (*env)->MonitorExit(env, obj_this);
- return nread;
+ nreturn = nread;
- error:
+ cleanup:
switch (state)
{
case GOTBUFFER:
free(nbuff);
/* fall-through */
+ case ACQUIRED:
+ osl_releasePipe(npipe);
+ /* fall-through */
case INMONITOR:
(*env)->MonitorExit(env, obj_this);
+ /* fall-through */
case START:
default:
break;
}
- return -1;
-}
+ return nreturn;
+ }
/*****************************************************************************/
/*
@@ -480,20 +481,20 @@ JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_writeJNI
ThrowException(env,
"java/lang/RuntimeException",
"native pipe cannot synchronize on the object");
- goto error;
+ goto cleanup;
}
state = INMONITOR;
/* check connection state */
npipe = getPipe(env, obj_this);
if ((*env)->ExceptionOccurred(env) != NULL)
- goto error;
+ goto cleanup;
if (npipe == NULL)
{
ThrowException(env,
"com/sun/star/io/IOException",
"native pipe is not connected");
- goto error;
+ goto cleanup;
}
nwrite = (*env)->GetArrayLength(env, buffer);
@@ -505,7 +506,7 @@ JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_writeJNI
ThrowException(env,
"java/lang/RuntimeException",
"native pipe out of memory");
- goto error;
+ goto cleanup;
}
state = GOTBUFFER;
@@ -517,22 +518,19 @@ JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_writeJNI
ThrowException(env,
"java/lang/RuntimeException",
"native pipe cannot synchronize on the object");
- goto error;
+ goto cleanup;
}
if (count != nwrite)
{
ThrowException(env,
"com/sun/star/io/IOException",
"native pipe: failed to write");
- goto error;
+ goto cleanup;
}
}
/* done */
- (*env)->ReleaseByteArrayElements(env, buffer, nbuff, JNI_ABORT);
- (*env)->MonitorExit(env, obj_this);
- return;
- error:
+ cleanup:
switch (state)
{
case GOTBUFFER:
@@ -540,6 +538,7 @@ JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_writeJNI
/* fall through */
case INMONITOR:
(*env)->MonitorExit(env, obj_this);
+ /* fall through */
case START:
default:
break;