{"id":19371376,"url":"https://github.com/amid68/xmalloc","last_synced_at":"2026-06-11T22:31:20.932Z","repository":{"id":257287060,"uuid":"852289884","full_name":"Amid68/xmalloc","owner":"Amid68","description":"The xmalloc project simplifies memory allocation in C by providing a custom wrapper around malloc() that automatically handles memory allocation failures, ensuring programs either succeed in allocating memory or terminate gracefully.","archived":false,"fork":false,"pushed_at":"2024-09-15T17:53:08.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-24T14:42:09.467Z","etag":null,"topics":["c","malloc","memory-allocation"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Amid68.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-04T14:56:37.000Z","updated_at":"2024-09-15T17:54:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"8309a5d4-3892-468e-a1ad-e3229c01d437","html_url":"https://github.com/Amid68/xmalloc","commit_stats":null,"previous_names":["amid68/xmalloc"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Amid68/xmalloc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Amid68%2Fxmalloc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Amid68%2Fxmalloc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Amid68%2Fxmalloc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Amid68%2Fxmalloc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Amid68","download_url":"https://codeload.github.com/Amid68/xmalloc/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Amid68%2Fxmalloc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34221150,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-11T02:00:06.485Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","malloc","memory-allocation"],"created_at":"2024-11-10T08:18:15.941Z","updated_at":"2026-06-11T22:31:20.910Z","avatar_url":"https://github.com/Amid68.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# xmalloc: Simplifying Memory Allocation in C\n\nThis project demonstrates the use of a custom memory allocation function called `xmalloc()` that simplifies the process of dynamic memory allocation in C. The function wraps around `malloc()`, handling error checking and making your code cleaner and easier to maintain.\n\n## Features\n\n- **`xmalloc()`**: A wrapper around `malloc()` that checks for memory allocation failures.\n- **Error handling**: If allocation fails, the program prints an error message and exits.\n- **Demo Programs**: Two demo programs (`xmalloc-demo-1.c` and `xmalloc-demo-2.c`) showcase the usage of `xmalloc()` and its benefits.\n\n## Files\n\n- `xmalloc.h`: Header file defining the `xmalloc()` macro.\n- `xmalloc.c`: Implementation of the `malloc_or_exit()` function.\n- `xmalloc-demo-1.c`: A demo showing basic usage of `xmalloc()`.\n- `xmalloc-demo-2.c`: A demo simulating memory allocation until failure (memory leak example).\n\n## Usage\n\n### Compilation\n\nTo compile the project, use the provided `Makefile`. It will compile the necessary object files and create executables for the demo programs.\n\n```bash\nmake\n```\n\n### Running the Demos\n\n1. **Run `xmalloc-demo-1`:**\n\n   ```bash\n   ./xmalloc-demo-1\n   ```\n\n   **Expected output:**\n\n   ```\n   Allocating 1000 bytes\n   Memory allocated\n   Memory freed\n   Allocating 0 bytes\n   xmalloc-demo-1.c: line 15: malloc() of 0 bytes failed\n   ```\n\n2. **Run `xmalloc-demo-2`:**\n\n   ```bash\n   ./xmalloc-demo-2\n   ```\n\n   **Note:** This program simulates a memory leak and will allocate large amounts of memory until it fails.\n\n### Cleaning Up\n\nTo remove the compiled files, use:\n\n```bash\nmake clean\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famid68%2Fxmalloc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famid68%2Fxmalloc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famid68%2Fxmalloc/lists"}