Changeset c43d7bd in rtems
- Timestamp:
- Nov 30, 2001, 12:03:15 PM (19 years ago)
- Branches:
- 4.10, 4.11, 4.8, 4.9, 5, master
- Children:
- 9e1ae79
- Parents:
- 7fe83de
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
c/src/exec/libcsupport/src/scandir.c
r7fe83de rc43d7bd 84 84 int (*dcomp) __P((const void *, const void *)); 85 85 { 86 register struct dirent *d, *p, **names; 86 register struct dirent *d = NULL; 87 register struct dirent *p = NULL; 88 register struct dirent **names = NULL; 87 89 register size_t nitems; 88 90 struct stat stb; 89 91 long arraysz; 90 DIR *dirp; 92 DIR *dirp = NULL; 93 int i; 91 94 92 95 if ((dirp = opendir(dirname)) == NULL) 93 96 return(-1); 94 97 if (fstat(dirp->dd_fd, &stb) < 0) 95 return(-1);98 goto cleanup_and_bail; 96 99 97 100 /* … … 102 105 names = (struct dirent **)malloc(arraysz * sizeof(struct dirent *)); 103 106 if (names == NULL) 104 return(-1);107 goto cleanup_and_bail; 105 108 106 109 nitems = 0; … … 113 116 p = (struct dirent *)malloc(DIRSIZ(d)); 114 117 if (p == NULL) 115 return(-1);118 goto cleanup_and_bail; 116 119 p->d_ino = d->d_ino; 117 120 p->d_reclen = d->d_reclen; … … 124 127 if (++nitems >= arraysz) { 125 128 if (fstat(dirp->dd_fd, &stb) < 0) 126 return(-1); /* just might have grown */129 goto cleanup_and_bail; /* just might have grown */ 127 130 arraysz = stb.st_size / 12; 128 131 names = (struct dirent **)realloc((char *)names, 129 132 arraysz * sizeof(struct dirent *)); 130 133 if (names == NULL) 131 return(-1);134 goto cleanup_and_bail; 132 135 } 133 136 names[nitems-1] = p; … … 139 142 *namelist = names; 140 143 return(nitems); 144 145 cleanup_and_bail: 146 147 if ( dirp ) 148 closedir( dirp ); 149 150 if ( names ) { 151 for (i=0; i < nitems; i++ ) 152 free( names[i] ); 153 free( names ); 154 } 155 156 return(-1); 141 157 } 142 158 -
c/src/lib/ChangeLog
r7fe83de rc43d7bd 1 2001-11-30 Jennifer Averett <jennifer@OARcorp.com> 2 3 This was tracked as PR88. 4 * libc/scandir.c: Fixed to perform cleanup on error conditions. 5 1 6 2001-11-07 Jennifer Averett <jennifer@OARcorp.com> 2 7 -
c/src/lib/libc/scandir.c
r7fe83de rc43d7bd 84 84 int (*dcomp) __P((const void *, const void *)); 85 85 { 86 register struct dirent *d, *p, **names; 86 register struct dirent *d = NULL; 87 register struct dirent *p = NULL; 88 register struct dirent **names = NULL; 87 89 register size_t nitems; 88 90 struct stat stb; 89 91 long arraysz; 90 DIR *dirp; 92 DIR *dirp = NULL; 93 int i; 91 94 92 95 if ((dirp = opendir(dirname)) == NULL) 93 96 return(-1); 94 97 if (fstat(dirp->dd_fd, &stb) < 0) 95 return(-1);98 goto cleanup_and_bail; 96 99 97 100 /* … … 102 105 names = (struct dirent **)malloc(arraysz * sizeof(struct dirent *)); 103 106 if (names == NULL) 104 return(-1);107 goto cleanup_and_bail; 105 108 106 109 nitems = 0; … … 113 116 p = (struct dirent *)malloc(DIRSIZ(d)); 114 117 if (p == NULL) 115 return(-1);118 goto cleanup_and_bail; 116 119 p->d_ino = d->d_ino; 117 120 p->d_reclen = d->d_reclen; … … 124 127 if (++nitems >= arraysz) { 125 128 if (fstat(dirp->dd_fd, &stb) < 0) 126 return(-1); /* just might have grown */129 goto cleanup_and_bail; /* just might have grown */ 127 130 arraysz = stb.st_size / 12; 128 131 names = (struct dirent **)realloc((char *)names, 129 132 arraysz * sizeof(struct dirent *)); 130 133 if (names == NULL) 131 return(-1);134 goto cleanup_and_bail; 132 135 } 133 136 names[nitems-1] = p; … … 139 142 *namelist = names; 140 143 return(nitems); 144 145 cleanup_and_bail: 146 147 if ( dirp ) 148 closedir( dirp ); 149 150 if ( names ) { 151 for (i=0; i < nitems; i++ ) 152 free( names[i] ); 153 free( names ); 154 } 155 156 return(-1); 141 157 } 142 158 -
cpukit/libcsupport/src/scandir.c
r7fe83de rc43d7bd 84 84 int (*dcomp) __P((const void *, const void *)); 85 85 { 86 register struct dirent *d, *p, **names; 86 register struct dirent *d = NULL; 87 register struct dirent *p = NULL; 88 register struct dirent **names = NULL; 87 89 register size_t nitems; 88 90 struct stat stb; 89 91 long arraysz; 90 DIR *dirp; 92 DIR *dirp = NULL; 93 int i; 91 94 92 95 if ((dirp = opendir(dirname)) == NULL) 93 96 return(-1); 94 97 if (fstat(dirp->dd_fd, &stb) < 0) 95 return(-1);98 goto cleanup_and_bail; 96 99 97 100 /* … … 102 105 names = (struct dirent **)malloc(arraysz * sizeof(struct dirent *)); 103 106 if (names == NULL) 104 return(-1);107 goto cleanup_and_bail; 105 108 106 109 nitems = 0; … … 113 116 p = (struct dirent *)malloc(DIRSIZ(d)); 114 117 if (p == NULL) 115 return(-1);118 goto cleanup_and_bail; 116 119 p->d_ino = d->d_ino; 117 120 p->d_reclen = d->d_reclen; … … 124 127 if (++nitems >= arraysz) { 125 128 if (fstat(dirp->dd_fd, &stb) < 0) 126 return(-1); /* just might have grown */129 goto cleanup_and_bail; /* just might have grown */ 127 130 arraysz = stb.st_size / 12; 128 131 names = (struct dirent **)realloc((char *)names, 129 132 arraysz * sizeof(struct dirent *)); 130 133 if (names == NULL) 131 return(-1);134 goto cleanup_and_bail; 132 135 } 133 136 names[nitems-1] = p; … … 139 142 *namelist = names; 140 143 return(nitems); 144 145 cleanup_and_bail: 146 147 if ( dirp ) 148 closedir( dirp ); 149 150 if ( names ) { 151 for (i=0; i < nitems; i++ ) 152 free( names[i] ); 153 free( names ); 154 } 155 156 return(-1); 141 157 } 142 158
Note: See TracChangeset
for help on using the changeset viewer.