Jelajahi Sumber

ZOOKEEPER-2558: Potential memory leak in recordio.c (Michael Han via phunt)

git-svn-id: https://svn.apache.org/repos/asf/zookeeper/trunk@1759735 13f79535-47bb-0310-9956-ffa450edef68
Patrick D. Hunt 8 tahun lalu
induk
melakukan
5f91336295
2 mengubah file dengan 11 tambahan dan 4 penghapusan
  1. 3 0
      CHANGES.txt
  2. 8 4
      src/c/src/recordio.c

+ 3 - 0
CHANGES.txt

@@ -362,6 +362,9 @@ BUGFIXES:
   ZOOKEEPER-2548: zooInspector does not start on Windows
   (Arshad Mohammad via phunt)
 
+  ZOOKEEPER-2558: Potential memory leak in recordio.c
+  (Michael Han via phunt)
+
 IMPROVEMENTS:
   ZOOKEEPER-2024 Major throughput improvement with mixed workloads (Kfir Lev-Ari via shralex)
 

+ 8 - 4
src/c/src/recordio.c

@@ -302,9 +302,11 @@ static struct oarchive oa_default = {
 
 struct iarchive *create_buffer_iarchive(char *buffer, int len)
 {
-    struct iarchive *ia = malloc(sizeof(*ia));
-    struct buff_struct *buff = malloc(sizeof(struct buff_struct));
+    struct iarchive *ia;
+    struct buff_struct *buff;
+    ia = malloc(sizeof(*ia));
     if (!ia) return 0;
+    buff = malloc(sizeof(struct buff_struct));
     if (!buff) {
         free(ia);
         return 0;
@@ -319,9 +321,11 @@ struct iarchive *create_buffer_iarchive(char *buffer, int len)
 
 struct oarchive *create_buffer_oarchive()
 {
-    struct oarchive *oa = malloc(sizeof(*oa));
-    struct buff_struct *buff = malloc(sizeof(struct buff_struct));
+    struct oarchive *oa;
+    struct buff_struct *buff;
+    oa = malloc(sizeof(*oa));
     if (!oa) return 0;
+    buff = malloc(sizeof(struct buff_struct));
     if (!buff) {
         free(oa);
         return 0;