Explorar o código

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

Bryan Drewery %!s(int64=8) %!d(string=hai) anos
pai
achega
804dbd44d3
Modificáronse 1 ficheiros con 2 adicións e 3 borrados
  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;
   }