src/solaris/native/java/lang/UNIXProcess_md.c
Print this page
*** 244,272 ****
splitPath(JNIEnv *env, const char *path)
{
const char *p, *q;
char **pathv;
int i;
int count = countOccurrences(path, ':') + 1;
pathv = NEW(char*, count+1);
pathv[count] = NULL;
for (p = path, i = 0; i < count; i++, p = q + 1) {
! for (q = p; (*q != ':') && (*q != '\0'); q++)
! ;
if (q == p) /* empty PATH component => "." */
pathv[i] = "./";
else {
int addSlash = ((*(q - 1)) != '/');
pathv[i] = NEW(char, q - p + addSlash + 1);
memcpy(pathv[i], p, q - p);
if (addSlash)
pathv[i][q - p] = '/';
pathv[i][q - p + addSlash] = '\0';
}
}
return (const char * const *) pathv;
}
/**
* Cached value of JVM's effective PATH.
* (We don't support putenv("PATH=...") in native code)
--- 244,284 ----
splitPath(JNIEnv *env, const char *path)
{
const char *p, *q;
char **pathv;
int i;
+ int k;
int count = countOccurrences(path, ':') + 1;
pathv = NEW(char*, count+1);
+ if (pathv == NULL)
+ return NULL;
+
pathv[count] = NULL;
for (p = path, i = 0; i < count; i++, p = q + 1) {
! for (q = p; (*q != ':') && (*q != '\0'); q++);
!
if (q == p) /* empty PATH component => "." */
pathv[i] = "./";
else {
int addSlash = ((*(q - 1)) != '/');
pathv[i] = NEW(char, q - p + addSlash + 1);
+ if (pathv[i] == NULL)
+ goto cleanUpMemory;
+
memcpy(pathv[i], p, q - p);
if (addSlash)
pathv[i][q - p] = '/';
pathv[i][q - p + addSlash] = '\0';
}
}
return (const char * const *) pathv;
+
+ cleanUpMemory:
+ for (k = 0; k <= i; k++)
+ free(pathv[k]);
+ return NULL;
}
/**
* Cached value of JVM's effective PATH.
* (We don't support putenv("PATH=...") in native code)
*** 484,493 ****
--- 496,508 ----
if (strcmp(s, "Unknown error") != 0)
detail = s;
}
/* ASCII Decimal representation uses 2.4 times as many bits as binary. */
errmsg = NEW(char, strlen(format) + strlen(detail) + 3 * sizeof(errnum));
+ if (errmsg == NULL)
+ return;
+
sprintf(errmsg, format, errnum, detail);
s = JNU_NewStringPlatform(env, errmsg);
if (s != NULL) {
jobject x = JNU_NewObjectByName(env, "java/io/IOException",
"(Ljava/lang/String;)V", s);