Fix menu double free
All checks were successful
build_test / build (push) Successful in 4m30s

This commit is contained in:
PoliEcho 2025-05-27 21:47:02 +02:00
parent 4b7644bd4f
commit ff9303861a
2 changed files with 24 additions and 25 deletions

View File

@ -2,7 +2,7 @@
CPPC = g++
CPPC_FLAGS = -std=c++23 -s -O3 -Wall -Wextra -lncurses -lmenu -lform -lcups
DEBUG_FLAGS = -ggdb -std=c++23 -Wall -lncurses -lmenu -lform -lcups
DEBUG_ASANITIZE = -fsanitize=address -ggdb -fno-omit-frame-pointer -std=c++23 -lncurses -lmenu -lcups -Wall -Wextra
DEBUG_ASANITIZE = -fsanitize=address -ggdb -fno-omit-frame-pointer -std=c++23 -lncurses -lmenu -lform -lcups -Wall -Wextra
SRC_PATH := src

View File

@ -1,13 +1,9 @@
#include <curses.h>
#include <menu.h>
#include <ncurses.h>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <vector>
#include "const.h"
@ -39,30 +35,33 @@ void menu() {
// Create items
complete_menu main_menu = {nullptr, nullptr, 0, nullptr};
main_menu_allocated.push_back({COMPLETE_MENU_TYPE, &main_menu, 1});
std::vector<ITEM*> items;
if (std::filesystem::exists(COMPLAINTS_DIR)) {
for (const auto& directroy_entry :
std::filesystem::directory_iterator(COMPLAINTS_DIR)) {
if (directroy_entry.is_regular_file()) {
std::string name_date[2];
std::stringstream ssfn(directroy_entry.path().filename().string());
for (uint8_t i = 0; i < 2; i++) {
std::getline(ssfn, name_date[i], '_');
{
std::vector<ITEM*> items;
if (std::filesystem::exists(COMPLAINTS_DIR)) {
for (const auto& directroy_entry :
std::filesystem::directory_iterator(COMPLAINTS_DIR)) {
if (directroy_entry.is_regular_file()) {
std::string name_date[2];
std::stringstream ssfn(directroy_entry.path().filename().string());
for (uint8_t i = 0; i < 2; i++) {
std::getline(ssfn, name_date[i], '_');
}
char* name = new char[name_date[0].length() + 1];
main_menu_allocated.push_back({GENERIC_TYPE, name, 1});
char* date = new char[name_date[1].length() + 1];
main_menu_allocated.push_back({GENERIC_TYPE, date, 1});
strcpy(name, name_date[0].c_str());
strcpy(date, name_date[1].c_str());
items.push_back(new_item(name, date));
}
char* name = new char[name_date[0].length() + 1];
main_menu_allocated.push_back({GENERIC_TYPE, name, 1});
char* date = new char[name_date[1].length() + 1];
main_menu_allocated.push_back({GENERIC_TYPE, date, 1});
strcpy(name, name_date[0].c_str());
strcpy(date, name_date[1].c_str());
items.push_back(new_item(name, date));
}
} else {
std::filesystem::create_directory(COMPLAINTS_DIR);
}
} else {
std::filesystem::create_directory(COMPLAINTS_DIR);
items.push_back(nullptr);
main_menu.items = new ITEM*[items.size()];
memcpy(main_menu.items, items.data(), (items.size() * sizeof(ITEM*)));
}
items.push_back(nullptr);
main_menu.items = items.data();
/* Crate menu */
main_menu.menu = new_menu(main_menu.items);