#1287 closed defect (duplicate)

forgot to renew point after allocating new memory

Reported by: hnhawk Owned by: Chris Johns
Priority: normal Milestone: 4.8
Component: score Version: 4.8
Severity: critical Keywords:
Cc: chrisj@… Blocked By:
Blocking:

Description

In function create_disk_entry()
When "if(major >= disktab_size)" is true, it has to allocate new memory to hold the bigger disk device table.
p = realloc(disktab, sizeof(struct disk_device_table) * newsize);
but you forget renew the disktab point.

The correct one should be:

static disk_device *
create_disk_entry(dev_t dev)
{

ACoreOs_device_major_number major;
ACoreOs_device_minor_number minor;
struct disk_device d;

ACoreOs_filesystem_split_dev_t (dev, major, minor);

if (major >= disktab_size) {

struct disk_device_table *p;
int newsize;
int i;
newsize = disktab_size * 2;
if (major >= newsize)

newsize = major + 1;

p = realloc(disktab, sizeof(struct disk_device_table) * newsize);
if (p == NULL)

return NULL;

p += disktab_size;
for (i = disktab_size; i < newsize; i++, p++) {

p->minor = NULL;
p->size = 0;

}
disktab_size = newsize;


/*renew the point, by huning*/
disktab=p;

}



if ((disktab[major].minor == NULL)

(minor >= disktab[major].size)) {
int newsize;
disk_device p;
int i;
int s = disktab[major].size;

if (s == 0)

newsize = DISKTAB_INITIAL_SIZE;

else

newsize = s * 2;

if (minor >= newsize)

newsize = minor + 1;

p = realloc(disktab[major].minor, sizeof(disk_device *) * newsize);
if (p == NULL)

return NULL;

disktab[major].minor = p;
p += s;
for (i = s; i < newsize; i++, p++)

*p = NULL;

disktab[major].size = newsize;

}

d = disktab[major].minor + minor;
if (*d == NULL) {

*d = calloc(1, sizeof(disk_device));

}
return *d;

}

Change History (2)

comment:1 Changed on Aug 4, 2008 at 6:11:46 PM by Joel Sherrill

Cc: Chris Johns added
Owner: changed from Joel Sherrill to Chris Johns

comment:2 Changed on Aug 6, 2008 at 3:49:49 AM by Chris Johns

Resolution: duplicate
Status: newclosed
Note: See TracTickets for help on using tickets.