Skip to content

Commit

Permalink
fix double freeing of furi string
Browse files Browse the repository at this point in the history
  • Loading branch information
panki27 committed Oct 9, 2022
1 parent 5f23b4b commit a9d6011
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions minesweeper.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,25 @@ static void render_callback(Canvas* const canvas, void* ctx) {
if (minesweeper_state == NULL) {
return;
}
FuriString* tempStr;
tempStr = furi_string_alloc();
furi_string_printf(tempStr, "Mines: %d", MINECOUNT - minesweeper_state->flags_set);
FuriString* mineStr;
FuriString* timeStr;
mineStr = furi_string_alloc();
timeStr = furi_string_alloc();

furi_string_printf(mineStr, "Mines: %d", MINECOUNT - minesweeper_state->flags_set);
canvas_set_font(canvas, FontSecondary);
canvas_draw_str_aligned(canvas, 0, 0, AlignLeft, AlignTop, furi_string_get_cstr(tempStr));
furi_string_free(tempStr);
canvas_draw_str_aligned(canvas, 0, 0, AlignLeft, AlignTop, furi_string_get_cstr(mineStr));

int seconds = 0;
int minutes = 0;
int minutes = 0;
if (minesweeper_state->game_started) {
uint32_t ticks_elapsed = furi_get_tick() - minesweeper_state->game_started_tick;
seconds = (int) ticks_elapsed / furi_kernel_get_tick_frequency();
minutes = (int) seconds / 60;
seconds = seconds % 60;
}
furi_string_printf(tempStr, "%01d:%02d", minutes, seconds);
canvas_draw_str_aligned(canvas, 128, 0, AlignRight, AlignTop, furi_string_get_cstr(tempStr));
furi_string_free(tempStr);
furi_string_printf(timeStr, "%01d:%02d", minutes, seconds);
canvas_draw_str_aligned(canvas, 128, 0, AlignRight, AlignTop, furi_string_get_cstr(timeStr));

for (int y = 0; y < PLAYFIELD_HEIGHT; y++) {
for (int x = 0; x < PLAYFIELD_WIDTH; x++) {
Expand Down Expand Up @@ -217,7 +219,9 @@ static void render_callback(Canvas* const canvas, void* ctx) {
}
}
}
furi_string_free(tempStr);

furi_string_free(mineStr);
furi_string_free(timeStr);
release_mutex((ValueMutex*)ctx, minesweeper_state);
}

Expand Down

0 comments on commit a9d6011

Please sign in to comment.