Преглед на файлове

set_unpack: Avoid unneeded malloc/free when there's no data

Bryan Drewery преди 8 години
родител
ревизия
804dbd44d3
променени са 1 файла, в които са добавени 2 реда и са изтрити 3 реда
  1. 2 3
      src/userent.cc

+ 2 - 3
src/userent.cc

@@ -305,15 +305,14 @@ static bool set_unpack(struct userrec *u, struct user_entry *e)
   char *key = NULL, *data = NULL;
 
   while (curr) {
-    t = (struct xtra_key *) calloc(1, sizeof(struct xtra_key));
     data = curr->extra;
     key = newsplit(&data);
     if (data[0]) {
+      t = (struct xtra_key *) calloc(1, sizeof(struct xtra_key));
       t->key = strdup(key);
       t->data = strdup(data);
       list_insert((struct xtra_key **) (&e->u.extra), t);
-    } else
-      free(t);
+    }
     curr = curr->next;
   }