free_map - 1Fr3aK2/Cub3d GitHub Wiki

📝 free_map

This function frees all dynamically allocated memory associated with a t_map structure, including its 2D map arrays and texture strings.

⚙️ Parameters

Parameter Type Description
map t_map* A pointer to the t_map structure to be freed.

🔁 Returns

Return value Description
void This function does not return a value. It frees memory.

📖 Description

The free_map function safely frees all memory associated with a t_map structure. It handles 2D arrays (map, buffer, temp_map) using the free_arr function and frees individual texture strings (north, south, east, west) using free. After freeing each component, it sets the corresponding pointer to NULL to avoid dangling pointers.

  • Checks if the map pointer is NULL before performing any operations.
  • Frees each 2D array using free_arr.
  • Frees individual texture strings if they exist and sets them to NULL.
  • Ensures that all memory inside the t_map structure is released safely, preventing memory leaks.

💡 Example Usage

t_map map = initialize_map(); // Assume this allocates memory for map
// Use the map for operations

free_map(&map); // Frees all allocated memory in the map structure

// After calling free_map, all pointers inside map are set to NULL