Created
January 6, 2019 22:39
-
-
Save markd2/097ab91de4f7b28c339834eb26d7b81e to your computer and use it in GitHub Desktop.
Revisions
-
Mark Dalrymple created this gist
Jan 6, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ #import <stdio.h> #import <stdlib.h> // clang -g -Wall -o malloc malloc.c int main(void) { int *blah = malloc(sizeof(int)); printf("blah on alloc: %x\n", *blah); *blah = 23; printf("blah after assignment: %x\n", *blah); free(blah); blah = malloc(sizeof(int)); printf("blah after free and malloc: %x\n", *blah); return 0; } /* % uname -a Darwin blah.local 17.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xn\ u-4570.71.2~1/RELEASE_X86_64 x86_64 % clang --version Apple LLVM version 10.0.0 (clang-1000.11.45.5) Target: x86_64-apple-darwin17.7.0 Thread model: posix InstalledDir: /Applications/Xcode-10-1.app/Contents/Developer/Toolchains/XcodeDefault.xctool\ chain/usr/bin % clang -g -Wall -o malloc malloc.c % ./malloc blah on alloc: 0 blah after assignment: 17 blah after free and malloc: 17 */