Преглед изворни кода

Userland: Use kmalloc_array() where appropriate

Andreas Kling пре 4 година
родитељ
комит
84656788bf

+ 1 - 1
Userland/Libraries/LibC/dirent.cpp

@@ -255,7 +255,7 @@ int scandir(const char* dir_name,
     }
 
     const int size = tmp_names.size();
-    auto names = (struct dirent**)malloc(size * sizeof(struct dirent*));
+    auto** names = static_cast<struct dirent**>(kmalloc_array(size, sizeof(struct dirent*)));
     for (auto i = 0; i < size; i++) {
         names[i] = tmp_names[i];
     }

+ 1 - 1
Userland/Libraries/LibC/stdlib.cpp

@@ -350,7 +350,7 @@ int putenv(char* new_var)
 
     // At this point, we need to append the new var.
     // 2 here: one for the new var, one for the sentinel value.
-    char** new_environ = (char**)malloc((environ_size + 2) * sizeof(char*));
+    auto** new_environ = static_cast<char**>(kmalloc_array(environ_size + 2, sizeof(char*)));
     if (new_environ == nullptr) {
         errno = ENOMEM;
         return -1;

+ 1 - 1
Userland/Libraries/LibGfx/BitmapFont.cpp

@@ -34,7 +34,7 @@ static_assert(sizeof(FontFileHeader) == 80);
 NonnullRefPtr<Font> BitmapFont::clone() const
 {
     size_t bytes_per_glyph = sizeof(u32) * glyph_height();
-    auto* new_rows = static_cast<unsigned*>(malloc(bytes_per_glyph * m_glyph_count));
+    auto* new_rows = static_cast<unsigned*>(kmalloc_array(m_glyph_count, bytes_per_glyph));
     memcpy(new_rows, m_rows, bytes_per_glyph * m_glyph_count);
     auto* new_widths = static_cast<u8*>(malloc(m_glyph_count));
     memcpy(new_widths, m_glyph_widths, m_glyph_count);

+ 11 - 11
Userland/Libraries/LibVideo/VP9/Parser.cpp

@@ -433,7 +433,7 @@ bool Parser::setup_past_independence()
     m_segmentation_abs_or_delta_update = false;
     if (m_prev_segment_ids)
         free(m_prev_segment_ids);
-    m_prev_segment_ids = static_cast<u8*>(malloc(m_mi_rows * m_mi_cols));
+    m_prev_segment_ids = static_cast<u8*>(kmalloc_array(m_mi_rows, m_mi_cols));
     m_loop_filter_delta_enabled = true;
     m_loop_filter_ref_deltas[IntraFrame] = 1;
     m_loop_filter_ref_deltas[LastFrame] = 0;
@@ -745,16 +745,16 @@ void Parser::allocate_tile_data()
     if (dimensions == m_allocated_dimensions)
         return;
     cleanup_tile_allocations();
-    m_skips = static_cast<bool*>(malloc(sizeof(bool) * dimensions));
-    m_tx_sizes = static_cast<TXSize*>(malloc(sizeof(TXSize) * dimensions));
-    m_mi_sizes = static_cast<u32*>(malloc(sizeof(u32) * dimensions));
-    m_y_modes = static_cast<u8*>(malloc(sizeof(u8) * dimensions));
-    m_segment_ids = static_cast<u8*>(malloc(sizeof(u8) * dimensions));
-    m_ref_frames = static_cast<ReferenceFrame*>(malloc(sizeof(ReferenceFrame) * dimensions * 2));
-    m_interp_filters = static_cast<InterpolationFilter*>(malloc(sizeof(InterpolationFilter) * dimensions));
-    m_mvs = static_cast<MV*>(malloc(sizeof(MV) * dimensions * 2));
-    m_sub_mvs = static_cast<MV*>(malloc(sizeof(MV) * dimensions * 2 * 4));
-    m_sub_modes = static_cast<IntraMode*>(malloc(sizeof(IntraMode) * dimensions * 4));
+    m_skips = static_cast<bool*>(kmalloc_array(dimensions, sizeof(bool)));
+    m_tx_sizes = static_cast<TXSize*>(kmalloc_array(dimensions, sizeof(TXSize)));
+    m_mi_sizes = static_cast<u32*>(kmalloc_array(dimensions, sizeof(u32)));
+    m_y_modes = static_cast<u8*>(kmalloc_array(dimensions, sizeof(u8)));
+    m_segment_ids = static_cast<u8*>(kmalloc_array(dimensions, sizeof(u8)));
+    m_ref_frames = static_cast<ReferenceFrame*>(kmalloc_array(dimensions, 2, sizeof(ReferenceFrame)));
+    m_interp_filters = static_cast<InterpolationFilter*>(kmalloc_array(dimensions, sizeof(InterpolationFilter)));
+    m_mvs = static_cast<MV*>(kmalloc_array(dimensions, 2, sizeof(MV)));
+    m_sub_mvs = static_cast<MV*>(kmalloc_array(dimensions, 8, sizeof(MV)));
+    m_sub_modes = static_cast<IntraMode*>(kmalloc_array(dimensions, 4, sizeof(IntraMode)));
     m_allocated_dimensions = dimensions;
 }