[PR #1143] [MERGED] fix: Removed double / unintended free #1715

Closed
opened 2026-01-29 15:23:49 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/TheAlgorithms/C/pull/1143
Author: @enzoveroneze
Created: 11/9/2022
Status: Merged
Merged: 11/10/2022
Merged by: @Panquesito7

Base: masterHead: patch-2


📝 Commits (1)

  • f0d7ddc Removed double / unintended free

📊 Changes

1 file changed (+1 additions, -2 deletions)

View changed files

📝 data_structures/dynamic_array/dynamic_array.c (+1 -2)

📄 Description

Description of Change

Call to free() after realloc() removed, avoiding undefined behavior.
The call to realloc() already frees the previously allocated memory if necessary.
By the man page of realloc(): "f the area pointed to was moved, a free(ptr) is done.",
and free(): "If free(ptr) has already been called before, undefined behavior occurs.".

Checklist

Notes: Removed call to free() after realloc()


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/TheAlgorithms/C/pull/1143 **Author:** [@enzoveroneze](https://github.com/enzoveroneze) **Created:** 11/9/2022 **Status:** ✅ Merged **Merged:** 11/10/2022 **Merged by:** [@Panquesito7](https://github.com/Panquesito7) **Base:** `master` ← **Head:** `patch-2` --- ### 📝 Commits (1) - [`f0d7ddc`](https://github.com/TheAlgorithms/C/commit/f0d7ddcbf31aa9bf40173ed8044474df2a570ed9) Removed double / unintended free ### 📊 Changes **1 file changed** (+1 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `data_structures/dynamic_array/dynamic_array.c` (+1 -2) </details> ### 📄 Description #### Description of Change **Call to free() after realloc() removed, avoiding undefined behavior.** The call to realloc() already frees the previously allocated memory if necessary. By the man page of realloc(): _"f the area pointed to was moved, a free(ptr) is done.",_ and free(): _"If free(ptr) has already been called before, undefined behavior occurs."._ <!-- Thank you for your Pull Request. Please provide a description above and review the requirements below. Contributors guide: https://github.com/TheAlgorithms/C/blob/master/CONTRIBUTING.md --> #### Checklist <!-- Remove items that do not apply. For completed items, change [ ] to [x]. --> - [ x] Added description of change(https://github.com/TheAlgorithms/C/blob/master/CONTRIBUTING.md#File-Name-guidelines) - [x ] PR title follows semantic [commit guidelines](https://github.com/TheAlgorithms/C/blob/master/CONTRIBUTING.md#Commit-Guidelines) - [x] Search previous suggestions before making a new one, as yours may be a duplicate. - [x] I acknowledge that all my contributions will be made under the project's license. Notes: Removed call to free() after realloc() --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 15:23:49 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/C#1715