Przeglądaj źródła

Check the result of malloc in string_list_add (#1495)

Michael Jones 1 rok temu
rodzic
commit
e45d846331
1 zmienionych plików z 7 dodań i 0 usunięć
  1. 7 0
      src/server/ns_turn_maps.c

+ 7 - 0
src/server/ns_turn_maps.c

@@ -838,9 +838,16 @@ static string_list *string_list_add(string_list *sl, const ur_string_map_key_typ
     return sl;
     return sl;
   }
   }
   string_elem *elem = (string_elem *)malloc(sizeof(string_elem));
   string_elem *elem = (string_elem *)malloc(sizeof(string_elem));
+  if (!elem) {
+    return sl;
+  }
   elem->list.next = sl;
   elem->list.next = sl;
   elem->key_size = strlen(key) + 1;
   elem->key_size = strlen(key) + 1;
   elem->key = (char *)malloc(elem->key_size);
   elem->key = (char *)malloc(elem->key_size);
+  if (!elem->key) {
+    free(elem);
+    return sl;
+  }
   memcpy(elem->key, key, elem->key_size);
   memcpy(elem->key, key, elem->key_size);
   elem->value = value;
   elem->value = value;
   return &(elem->list);
   return &(elem->list);