{"id":17693039,"url":"https://github.com/nihlus/zalloc","last_synced_at":"2025-05-13T02:49:51.065Z","repository":{"id":83764224,"uuid":"189072280","full_name":"Nihlus/zalloc","owner":"Nihlus","description":"zalloc is a safety- and security-oriented wrapper around malloc.","archived":false,"fork":false,"pushed_at":"2021-05-24T18:56:18.000Z","size":61,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-01T06:02:44.973Z","etag":null,"topics":["allocator","c","calloc","hacktoberfest","malloc","safety","security"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Nihlus.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":"2019-05-28T17:19:57.000Z","updated_at":"2025-03-11T10:45:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"ac03d710-a618-4193-811c-28d912236c3f","html_url":"https://github.com/Nihlus/zalloc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nihlus%2Fzalloc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nihlus%2Fzalloc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nihlus%2Fzalloc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nihlus%2Fzalloc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nihlus","download_url":"https://codeload.github.com/Nihlus/zalloc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253862736,"owners_count":21975583,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["allocator","c","calloc","hacktoberfest","malloc","safety","security"],"created_at":"2024-10-24T13:44:04.386Z","updated_at":"2025-05-13T02:49:51.037Z","avatar_url":"https://github.com/Nihlus.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"zalloc\n======\n\nAn allocation library for safety-over-speed enthusiats.\n\n### What?\n`zalloc` is a tiny dynamic allocation library for C/C++ that wraps the typical `calloc` and `free` functions to add\nensured correctness features. Principally, `zalloc` has a well-defined interface and aims to provide no undefined \nbehaviour for any permutation of its inputs our outputs.\n\n### How?\n`zalloc` provides three functions - `zalloc`, `zfree`, and `zsize`.\n\n------------------------------------------------------------------------------------------------------------------------\n`void* zalloc(size_t size)`\n\nAllocates a block of zero-initialized memory. \n\n------------------------------------------------------------------------------------------------------------------------\n`bool zfree(void** mem)`\n\nFrees a block of memory allocated by `zalloc`. This zeroes the allocated region, and sets the referenced pointer to null.\n\n------------------------------------------------------------------------------------------------------------------------\n`size_t zsize(const void* mem)`\n\nDetermines the size of a memory block allocated by `zalloc`.\n\n### Benefits?\nAll memory allocated by `zalloc` is zero-initialized on allocation, and is provided to the user as such. Nonsane \nallocation requests (such as zero-size allocations) are rejected. \n\nWhen memory blocks allocated with `zalloc` are freed, they are once again zeroed to erase potentially sensitive data and\nto improve fault detection. Instead of reading garbage data in the case of a fault condition, the presence of \ncontinuous regions of zeroed memory can be clearly observed.\n\nFurthermore, `zfree` guards against double-frees, and repeatedly freeing an already freed block has no effect.  Freeing\n`null` has no effect. To prevent pointer reuse, `zfree` also explicitly nulls out the pointer it has just freed.\n\n`zsize` can be used to retrieve the size of an allocated memory region after the fact.\n\n### Implementation?\nAll memory blocks allocated by `zalloc` have a memory header located directly before the user-allocated memory pointed\nto by the pointer returned by `zalloc`.  This header contains information about the memory block that `zalloc` uses to\nfree the memory in a safe and well-defined manner.\n\nCurrently, this header contains two fields - a magic signature that marks the region as being allocated by `zalloc`, and\nthe byte size of the following memory region. The header and its layout is to be considered an internal implementation\ndetail, and should not be accessed by consumers.\n\n### Drawbacks?\nAllocation and deallocation incurs a small CPU overhead, because the memory is explicitly zeroed in both operations.\n\nAllocated memory blocks carry a memory overhead of 12 bytes per block.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnihlus%2Fzalloc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnihlus%2Fzalloc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnihlus%2Fzalloc/lists"}