76 |
|
"ntfs"} |
77 |
|
#endif |
78 |
|
|
79 |
< |
char *copy_string(char *orig_ptr, const char *newtext){ |
79 |
> |
static char *copy_string(char **dest, const char *src) { |
80 |
> |
char *new; |
81 |
|
|
82 |
< |
/* Maybe free if not NULL, and strdup rather than realloc and strcpy? */ |
83 |
< |
orig_ptr=realloc(orig_ptr, (1+strlen(newtext))); |
84 |
< |
if(orig_ptr==NULL){ |
85 |
< |
return NULL; |
85 |
< |
} |
86 |
< |
strcpy(orig_ptr, newtext); |
82 |
> |
new = realloc(*dest, strlen(src) + 1); |
83 |
> |
if (new == NULL) { |
84 |
> |
return NULL; |
85 |
> |
} |
86 |
|
|
87 |
< |
return orig_ptr; |
87 |
> |
strcpy(new, src); |
88 |
> |
*dest = new; |
89 |
> |
return new; |
90 |
|
} |
91 |
|
|
92 |
|
static void disk_stat_init(disk_stat_t *d) { |
178 |
|
disk_ptr=disk_stats+num_disks; |
179 |
|
|
180 |
|
#ifdef ALLBSD |
181 |
< |
if((disk_ptr->device_name=copy_string(disk_ptr->device_name, mp->f_mntfromname))==NULL){ |
181 |
> |
if (copy_string(&disk_ptr->device_name, mp->f_mntfromname) == NULL) { |
182 |
|
return NULL; |
183 |
|
} |
184 |
< |
|
184 |
< |
if((disk_ptr->fs_type=copy_string(disk_ptr->fs_type, mp->f_fstypename))==NULL){ |
184 |
> |
if (copy_string(&disk_ptr->fs_type, mp->f_fstypename) == NULL) { |
185 |
|
return NULL; |
186 |
|
} |
187 |
< |
|
188 |
< |
if((disk_ptr->mnt_point=copy_string(disk_ptr->mnt_point, mp->f_mntonname))==NULL){ |
187 |
> |
if (copy_string(&disk_ptr->mnt_point, mp->f_mntonname) == NULL) { |
188 |
|
return NULL; |
189 |
|
} |
190 |
|
|
198 |
|
disk_ptr->used_inodes=disk_ptr->total_inodes-disk_ptr->free_inodes; |
199 |
|
#endif |
200 |
|
#if defined(LINUX) || defined(CYGWIN) |
201 |
< |
if((disk_ptr->device_name=copy_string(disk_ptr->device_name, mp->mnt_fsname))==NULL){ |
201 |
> |
if (copy_string(&disk_ptr->device_name, mp->mnt_fsname) == NULL) { |
202 |
|
return NULL; |
203 |
|
} |
204 |
|
|
205 |
< |
if((disk_ptr->fs_type=copy_string(disk_ptr->fs_type, mp->mnt_type))==NULL){ |
205 |
> |
if (copy_string(&disk_ptr->fs_type, mp->mnt_type) == NULL) { |
206 |
|
return NULL; |
207 |
|
} |
208 |
|
|
209 |
< |
if((disk_ptr->mnt_point=copy_string(disk_ptr->mnt_point, mp->mnt_dir))==NULL){ |
209 |
> |
if (copy_string(&disk_ptr->mnt_point, mp->mnt_dir) == NULL) { |
210 |
|
return NULL; |
211 |
|
} |
212 |
|
disk_ptr->size = (long long)fs.f_bsize * (long long)fs.f_blocks; |
220 |
|
#endif |
221 |
|
|
222 |
|
#ifdef SOLARIS |
224 |
– |
/* Memory leak in event of realloc failing */ |
223 |
|
/* Maybe make this char[bigenough] and do strncpy's and put a null in the end? |
224 |
|
* Downside is its a bit hungry for a lot of mounts, as MNT_MAX_SIZE would prob |
225 |
|
* be upwards of a k each |
226 |
|
*/ |
227 |
< |
if((disk_ptr->device_name=copy_string(disk_ptr->device_name, mp.mnt_special))==NULL){ |
227 |
> |
if (copy_string(&disk_ptr->device_name, mp.mnt_special) == NULL) { |
228 |
|
return NULL; |
229 |
|
} |
230 |
|
|
231 |
< |
if((disk_ptr->fs_type=copy_string(disk_ptr->fs_type, mp.mnt_fstype))==NULL){ |
231 |
> |
if (copy_string(&disk_ptr->fs_type, mp.mnt_fstype) == NULL) { |
232 |
|
return NULL; |
233 |
|
} |
234 |
|
|
235 |
< |
if((disk_ptr->mnt_point=copy_string(disk_ptr->mnt_point, mp.mnt_mountp))==NULL){ |
235 |
> |
if (copy_string(&disk_ptr->mnt_point, mp.mnt_mountp) == NULL) { |
236 |
|
return NULL; |
237 |
|
} |
238 |
|
|