Skip to contentSkip to conversation

hw/smbus_eeprom.c : fix memory leak

PATCH In review Li Zhi Hui 2 participants 3 messages Dec 2, 2011

lore
Share & tools
lore

Li Zhi Hui

author
#0 lore raw

PATCH 1/1 hw/smbus_eeprom.c : fix memory leak

---
 hw/smbus_eeprom.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
hw/smbus_eeprom.c +1 -0
index 5d080ab..d66fbbc 100644
@@ -142,4 +142,5 @@ void smbus_eeprom_init(i2c_bus *smbus, int nb_eeprom,
         qdev_prop_set_ptr(eeprom, "data", eeprom_buf + (i * 256));
         qdev_init_nofail(eeprom);
     }
+    g_free(eeprom_buf);
 }
Signature · 1 line
1.7.4.1
#1 lore raw
Quoted 10 lines · Li Zhi Hui
---
  hw/smbus_eeprom.c |    1 +
  1 files changed, 1 insertions(+), 0 deletions(-)
hw/smbus_eeprom.c +0 -0
index 5d080ab..d66fbbc 100644

hw/smbus_eeprom.c void smbus_eeprom_init(i2c_bus *smbus, int nb_eeprom, · line 146

Quoted 5 lines
hw/smbus_eeprom.c +1 -0
@@ -142,4 +142,5 @@ void smbus_eeprom_init(i2c_bus *smbus, int nb_eeprom,
          qdev_prop_set_ptr(eeprom, "data", eeprom_buf + (i * 256));
          qdev_init_nofail(eeprom);
      }
+    g_free(eeprom_buf);
  }

The memory pointed by eeprom_buf is used as 'data' buf of 8 SMBusEEPROMDevice after initialization. And it calls qdev_init_nofail, which will exit on failure. it should be ok to leave it there. Anyway, you shouldn't free it in the initialization.

Mark.

author
#2 lore raw
Quoted 21 lines · Mark Wu
Quoted 10 lines · Li Zhi Hui

---
hw/smbus_eeprom.c | 1 +

1 files changed, 1 insertions(+), 0 deletions(-)
hw/smbus_eeprom.c +0 -0
index 5d080ab..d66fbbc 100644

hw/smbus_eeprom.c void smbus_eeprom_init(i2c_bus *smbus, int nb_eeprom, · line 146

Quoted 5 lines
hw/smbus_eeprom.c +1 -0
@@ -142,4 +142,5 @@ void smbus_eeprom_init(i2c_bus *smbus, int nb_eeprom,
 qdev_prop_set_ptr(eeprom, "data", eeprom_buf + (i * 256));
 qdev_init_nofail(eeprom);
 }
+ g_free(eeprom_buf);
 }

The memory pointed by eeprom_buf is used as 'data' buf of 8 SMBusEEPROMDevice after initialization. And it calls qdev_init_nofail, which will exit on failure. it should be ok to leave it there. Anyway, you shouldn't free it in the initialization.

Quoted 3 lines

Mark.

I'm afraid I was too fast when I sent a patch with memory leak, and don't look it carefully , It was a pointer to a pointer.

I agree with Mark Wu.