- Make Disk_Names() behave as documented in libdisk(3): return an array
of disk names, where you must free each pointer, as well as the array by hand. [1] - Destaticize "disks" in Disk_Names, it has no reasons to be static. PR: kern/96077 [1] PR: kern/114110 [1] MFC after: 1 month Approved by: rwatson (mentor)
This commit is contained in:
parent
e2442c2081
commit
b08b3ca18f
@ -189,10 +189,10 @@ char **
|
||||
Disk_Names()
|
||||
{
|
||||
int disk_cnt;
|
||||
static char **disks;
|
||||
char **disks;
|
||||
int error;
|
||||
size_t listsize;
|
||||
char *disklist;
|
||||
char *disklist, *disk1, *disk2;
|
||||
|
||||
error = sysctlbyname("kern.disks", NULL, &listsize, NULL, 0);
|
||||
if (error) {
|
||||
@ -206,7 +206,7 @@ Disk_Names()
|
||||
disks = malloc(sizeof *disks * (1 + MAX_NO_DISKS));
|
||||
if (disks == NULL)
|
||||
return NULL;
|
||||
disklist = (char *)malloc(listsize + 1);
|
||||
disk1 = disklist = (char *)malloc(listsize + 1);
|
||||
if (disklist == NULL) {
|
||||
free(disks);
|
||||
return NULL;
|
||||
@ -220,11 +220,20 @@ Disk_Names()
|
||||
return NULL;
|
||||
}
|
||||
for (disk_cnt = 0; disk_cnt < MAX_NO_DISKS; disk_cnt++) {
|
||||
disks[disk_cnt] = strsep(&disklist, " ");
|
||||
if (disks[disk_cnt] == NULL)
|
||||
disk2 = strsep(&disk1, " ");
|
||||
if (disk2 == NULL)
|
||||
break;
|
||||
disks[disk_cnt] = strdup(disk2);
|
||||
if (disks[disk_cnt] == NULL) {
|
||||
for (disk_cnt--; disk_cnt >= 0; disk_cnt--)
|
||||
free(disks[disk_cnt]);
|
||||
free(disklist);
|
||||
free(disks);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
qsort(disks, disk_cnt, sizeof(char*), qstrcmp);
|
||||
free(disklist);
|
||||
return disks;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user