src/solaris/native/java/lang/UNIXProcess_md.c
Print this page
*** 243,265 ****
static const char * const *
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';
}
--- 243,292 ----
static const char * const *
splitPath(JNIEnv *env, const char *path)
{
const char *p, *q;
char **pathv;
! const char *cwd = "./";
! size_t i;
! size_t 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] = NEW(char,sizeof(cwd));
!
! if (pathv[i] == NULL) {
!
! while(i)
! free(pathv[--i]);
!
! free(pathv);
! return NULL;
! }
!
! memcpy(pathv[i],cwd,sizeof(cwd));
! }
else {
int addSlash = ((*(q - 1)) != '/');
pathv[i] = NEW(char, q - p + addSlash + 1);
+
+ if (pathv[i] == NULL) {
+
+ while(i)
+ free(pathv[--i]);
+
+ free(pathv);
+ return NULL;
+ }
+
memcpy(pathv[i], p, q - p);
if (addSlash)
pathv[i][q - p] = '/';
pathv[i][q - p + addSlash] = '\0';
}
*** 484,493 ****
--- 511,523 ----
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);