Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f17b971a authored by Elliott Hughes's avatar Elliott Hughes
Browse files

More native code cleanup.

Use ScopedUtfChars (fixes a leak in TrafficStats, and fixes a crash in Wifi in
a case where GetStringChars could have been called with a pending exception).

Change-Id: I3465ff392b4038dfdafa6af80ec1314cc6d6a11c
parent 83b61471
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
#include <android_runtime/AndroidRuntime.h>
#include <cutils/logger.h>
#include <jni.h>
#include <ScopedUtfChars.h>
#include <utils/misc.h>
#include <utils/Log.h>

@@ -130,13 +131,14 @@ static jlong getMobileRxBytes(JNIEnv* env, jobject clazz) {
            "/sys/class/net/ppp0/statistics/rx_bytes");
}

static jlong getData(JNIEnv* env, char *what, jstring interface) {
    char filename[80];
    jboolean isCopy;

    const char *interfaceStr = env->GetStringUTFChars(interface, &isCopy);
    snprintf(filename, sizeof(filename), "/sys/class/net/%s/statistics/%s", interfaceStr, what);
static jlong getData(JNIEnv* env, const char* what, jstring javaInterface) {
    ScopedUtfChars interface(env, javaInterface);
    if (interface.c_str() == NULL) {
        return -1;
    }

    char filename[80];
    snprintf(filename, sizeof(filename), "/sys/class/net/%s/statistics/%s", interface.c_str(), what);
    return readNumber(filename);
}

+169 −242

File changed.

Preview size limit exceeded, changes collapsed.