{"action":"created","comment":{"url":"https://api.github.com/repos/cpputest/cpputest/pulls/comments/36621992","id":36621992,"diff_hunk":"@@ -0,0 +1,217 @@\n+/*\n+ * Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions are met:\n+ *     * Redistributions of source code must retain the above copyright\n+ *       notice, this list of conditions and the following disclaimer.\n+ *     * Redistributions in binary form must reproduce the above copyright\n+ *       notice, this list of conditions and the following disclaimer in the\n+ *       documentation and/or other materials provided with the distribution.\n+ *     * Neither the name of the <organization> nor the\n+ *       names of its contributors may be used to endorse or promote products\n+ *       derived from this software without specific prior written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY\n+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n+ * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY\n+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\n+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\n+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include \"CppUTest/TestHarness.h\"\n+#include \"CppUTest/FailableMemoryAllocator.h\"\n+#include \"CppUTest/TestTestingFixture.h\"\n+\n+\n+// Allocator must be global. Otherwise, it does not exist when memory leak detector\n+// reports memory leaks.\n+static FailableMemoryAllocator failableMallocAllocator(\"Failable Malloc Allocator\", \"malloc\", \"free\");\n+static FailableMemoryAllocator failableNewAllocator(\"Failable New Allocator\", \"new\", \"delete\");\n+static FailableMemoryAllocator failableNewArrayAllocator(\"Failable New [] Allocator\", \"new []\", \"delete []\");\n+\n+\n+#if CPPUTEST_USE_MEM_LEAK_DETECTION\n+\n+TEST_GROUP(FailableMemoryAllocator)\n+{\n+    void setup()\n+    {\n+        failableMallocAllocator.clearFailedAllocations();\n+        failableNewAllocator.clearFailedAllocations();\n+        failableNewArrayAllocator.clearFailedAllocations();\n+\n+        setCurrentMallocAllocator(&failableMallocAllocator);\n+        setCurrentNewAllocator(&failableNewAllocator);\n+        setCurrentNewArrayAllocator(&failableNewArrayAllocator);\n+    }\n+    void teardown()\n+    {\n+        setCurrentMallocAllocatorToDefault();\n+        setCurrentNewAllocatorToDefault();\n+        setCurrentNewArrayAllocatorToDefault();\n+    }\n+};\n+\n+#if CPPUTEST_USE_MALLOC_MACROS\n+TEST(FailableMemoryAllocator, MallocWorksNormallyIfNotAskedToFail)\n+{\n+    int *memory = (int*)malloc(sizeof(int));\n+    *memory = 1;","path":"tests/FailableMemoryAllocatorTest.cpp","position":65,"original_position":65,"commit_id":"d60e0e4b0019f5a54d3cafb09ba30578e86bb2ad","original_commit_id":"2db48139c4fe4a2737ad23070ce6e3f96560f87c","user":{"login":"jkohvakk","id":1439614,"avatar_url":"https://avatars.githubusercontent.com/u/1439614?v=3","gravatar_id":"","url":"https://api.github.com/users/jkohvakk","html_url":"https://github.com/jkohvakk","followers_url":"https://api.github.com/users/jkohvakk/followers","following_url":"https://api.github.com/users/jkohvakk/following{/other_user}","gists_url":"https://api.github.com/users/jkohvakk/gists{/gist_id}","starred_url":"https://api.github.com/users/jkohvakk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jkohvakk/subscriptions","organizations_url":"https://api.github.com/users/jkohvakk/orgs","repos_url":"https://api.github.com/users/jkohvakk/repos","events_url":"https://api.github.com/users/jkohvakk/events{/privacy}","received_events_url":"https://api.github.com/users/jkohvakk/received_events","type":"User","site_admin":false},"body":"Well. It tests that the memory returned is writable and not just some random address. At least some level. But if you think it is not useful, I will remove it.","created_at":"2015-08-10T11:32:32Z","updated_at":"2015-08-10T11:32:32Z","html_url":"https://github.com/cpputest/cpputest/pull/752#discussion_r36621992","pull_request_url":"https://api.github.com/repos/cpputest/cpputest/pulls/752","_links":{"self":{"href":"https://api.github.com/repos/cpputest/cpputest/pulls/comments/36621992"},"html":{"href":"https://github.com/cpputest/cpputest/pull/752#discussion_r36621992"},"pull_request":{"href":"https://api.github.com/repos/cpputest/cpputest/pulls/752"}}},"pull_request":{"url":"https://api.github.com/repos/cpputest/cpputest/pulls/752","id":41646164,"html_url":"https://github.com/cpputest/cpputest/pull/752","diff_url":"https://github.com/cpputest/cpputest/pull/752.diff","patch_url":"https://github.com/cpputest/cpputest/pull/752.patch","issue_url":"https://api.github.com/repos/cpputest/cpputest/issues/752","number":752,"state":"open","locked":false,"title":"FailableMemoryAllocator","user":{"login":"jkohvakk","id":1439614,"avatar_url":"https://avatars.githubusercontent.com/u/1439614?v=3","gravatar_id":"","url":"https://api.github.com/users/jkohvakk","html_url":"https://github.com/jkohvakk","followers_url":"https://api.github.com/users/jkohvakk/followers","following_url":"https://api.github.com/users/jkohvakk/following{/other_user}","gists_url":"https://api.github.com/users/jkohvakk/gists{/gist_id}","starred_url":"https://api.github.com/users/jkohvakk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jkohvakk/subscriptions","organizations_url":"https://api.github.com/users/jkohvakk/orgs","repos_url":"https://api.github.com/users/jkohvakk/repos","events_url":"https://api.github.com/users/jkohvakk/events{/privacy}","received_events_url":"https://api.github.com/users/jkohvakk/received_events","type":"User","site_admin":false},"body":"Hi,\r\n\r\nI cleaned up and generalized the FailableMemoryAllocator. Please have a look.\r\n\r\n.Janne","created_at":"2015-08-05T06:10:21Z","updated_at":"2015-08-10T11:32:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e53871779cc172586d7e74a33841ea45a00bf0bd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cpputest/cpputest/pulls/752/commits","review_comments_url":"https://api.github.com/repos/cpputest/cpputest/pulls/752/comments","review_comment_url":"https://api.github.com/repos/cpputest/cpputest/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cpputest/cpputest/issues/752/comments","statuses_url":"https://api.github.com/repos/cpputest/cpputest/statuses/d60e0e4b0019f5a54d3cafb09ba30578e86bb2ad","head":{"label":"jkohvakk:master","ref":"master","sha":"d60e0e4b0019f5a54d3cafb09ba30578e86bb2ad","user":{"login":"jkohvakk","id":1439614,"avatar_url":"https://avatars.githubusercontent.com/u/1439614?v=3","gravatar_id":"","url":"https://api.github.com/users/jkohvakk","html_url":"https://github.com/jkohvakk","followers_url":"https://api.github.com/users/jkohvakk/followers","following_url":"https://api.github.com/users/jkohvakk/following{/other_user}","gists_url":"https://api.github.com/users/jkohvakk/gists{/gist_id}","starred_url":"https://api.github.com/users/jkohvakk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jkohvakk/subscriptions","organizations_url":"https://api.github.com/users/jkohvakk/orgs","repos_url":"https://api.github.com/users/jkohvakk/repos","events_url":"https://api.github.com/users/jkohvakk/events{/privacy}","received_events_url":"https://api.github.com/users/jkohvakk/received_events","type":"User","site_admin":false},"repo":{"id":38369448,"name":"cpputest","full_name":"jkohvakk/cpputest","owner":{"login":"jkohvakk","id":1439614,"avatar_url":"https://avatars.githubusercontent.com/u/1439614?v=3","gravatar_id":"","url":"https://api.github.com/users/jkohvakk","html_url":"https://github.com/jkohvakk","followers_url":"https://api.github.com/users/jkohvakk/followers","following_url":"https://api.github.com/users/jkohvakk/following{/other_user}","gists_url":"https://api.github.com/users/jkohvakk/gists{/gist_id}","starred_url":"https://api.github.com/users/jkohvakk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jkohvakk/subscriptions","organizations_url":"https://api.github.com/users/jkohvakk/orgs","repos_url":"https://api.github.com/users/jkohvakk/repos","events_url":"https://api.github.com/users/jkohvakk/events{/privacy}","received_events_url":"https://api.github.com/users/jkohvakk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jkohvakk/cpputest","description":"CppUTest unit testing and mocking framework for C/C++","fork":true,"url":"https://api.github.com/repos/jkohvakk/cpputest","forks_url":"https://api.github.com/repos/jkohvakk/cpputest/forks","keys_url":"https://api.github.com/repos/jkohvakk/cpputest/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jkohvakk/cpputest/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jkohvakk/cpputest/teams","hooks_url":"https://api.github.com/repos/jkohvakk/cpputest/hooks","issue_events_url":"https://api.github.com/repos/jkohvakk/cpputest/issues/events{/number}","events_url":"https://api.github.com/repos/jkohvakk/cpputest/events","assignees_url":"https://api.github.com/repos/jkohvakk/cpputest/assignees{/user}","branches_url":"https://api.github.com/repos/jkohvakk/cpputest/branches{/branch}","tags_url":"https://api.github.com/repos/jkohvakk/cpputest/tags","blobs_url":"https://api.github.com/repos/jkohvakk/cpputest/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jkohvakk/cpputest/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jkohvakk/cpputest/git/refs{/sha}","trees_url":"https://api.github.com/repos/jkohvakk/cpputest/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jkohvakk/cpputest/statuses/{sha}","languages_url":"https://api.github.com/repos/jkohvakk/cpputest/languages","stargazers_url":"https://api.github.com/repos/jkohvakk/cpputest/stargazers","contributors_url":"https://api.github.com/repos/jkohvakk/cpputest/contributors","subscribers_url":"https://api.github.com/repos/jkohvakk/cpputest/subscribers","subscription_url":"https://api.github.com/repos/jkohvakk/cpputest/subscription","commits_url":"https://api.github.com/repos/jkohvakk/cpputest/commits{/sha}","git_commits_url":"https://api.github.com/repos/jkohvakk/cpputest/git/commits{/sha}","comments_url":"https://api.github.com/repos/jkohvakk/cpputest/comments{/number}","issue_comment_url":"https://api.github.com/repos/jkohvakk/cpputest/issues/comments{/number}","contents_url":"https://api.github.com/repos/jkohvakk/cpputest/contents/{+path}","compare_url":"https://api.github.com/repos/jkohvakk/cpputest/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jkohvakk/cpputest/merges","archive_url":"https://api.github.com/repos/jkohvakk/cpputest/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jkohvakk/cpputest/downloads","issues_url":"https://api.github.com/repos/jkohvakk/cpputest/issues{/number}","pulls_url":"https://api.github.com/repos/jkohvakk/cpputest/pulls{/number}","milestones_url":"https://api.github.com/repos/jkohvakk/cpputest/milestones{/number}","notifications_url":"https://api.github.com/repos/jkohvakk/cpputest/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jkohvakk/cpputest/labels{/name}","releases_url":"https://api.github.com/repos/jkohvakk/cpputest/releases{/id}","created_at":"2015-07-01T12:16:30Z","updated_at":"2015-07-01T12:16:32Z","pushed_at":"2015-08-10T06:11:36Z","git_url":"git://github.com/jkohvakk/cpputest.git","ssh_url":"git@github.com:jkohvakk/cpputest.git","clone_url":"https://github.com/jkohvakk/cpputest.git","svn_url":"https://github.com/jkohvakk/cpputest","homepage":"http://cpputest.github.com","size":9240,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"cpputest:master","ref":"master","sha":"dc699d0fbd596feee5f110e2063f85df7eb9c108","user":{"login":"cpputest","id":2120339,"avatar_url":"https://avatars.githubusercontent.com/u/2120339?v=3","gravatar_id":"","url":"https://api.github.com/users/cpputest","html_url":"https://github.com/cpputest","followers_url":"https://api.github.com/users/cpputest/followers","following_url":"https://api.github.com/users/cpputest/following{/other_user}","gists_url":"https://api.github.com/users/cpputest/gists{/gist_id}","starred_url":"https://api.github.com/users/cpputest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpputest/subscriptions","organizations_url":"https://api.github.com/users/cpputest/orgs","repos_url":"https://api.github.com/users/cpputest/repos","events_url":"https://api.github.com/users/cpputest/events{/privacy}","received_events_url":"https://api.github.com/users/cpputest/received_events","type":"Organization","site_admin":false},"repo":{"id":5269602,"name":"cpputest","full_name":"cpputest/cpputest","owner":{"login":"cpputest","id":2120339,"avatar_url":"https://avatars.githubusercontent.com/u/2120339?v=3","gravatar_id":"","url":"https://api.github.com/users/cpputest","html_url":"https://github.com/cpputest","followers_url":"https://api.github.com/users/cpputest/followers","following_url":"https://api.github.com/users/cpputest/following{/other_user}","gists_url":"https://api.github.com/users/cpputest/gists{/gist_id}","starred_url":"https://api.github.com/users/cpputest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpputest/subscriptions","organizations_url":"https://api.github.com/users/cpputest/orgs","repos_url":"https://api.github.com/users/cpputest/repos","events_url":"https://api.github.com/users/cpputest/events{/privacy}","received_events_url":"https://api.github.com/users/cpputest/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cpputest/cpputest","description":"CppUTest unit testing and mocking framework for C/C++","fork":false,"url":"https://api.github.com/repos/cpputest/cpputest","forks_url":"https://api.github.com/repos/cpputest/cpputest/forks","keys_url":"https://api.github.com/repos/cpputest/cpputest/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cpputest/cpputest/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cpputest/cpputest/teams","hooks_url":"https://api.github.com/repos/cpputest/cpputest/hooks","issue_events_url":"https://api.github.com/repos/cpputest/cpputest/issues/events{/number}","events_url":"https://api.github.com/repos/cpputest/cpputest/events","assignees_url":"https://api.github.com/repos/cpputest/cpputest/assignees{/user}","branches_url":"https://api.github.com/repos/cpputest/cpputest/branches{/branch}","tags_url":"https://api.github.com/repos/cpputest/cpputest/tags","blobs_url":"https://api.github.com/repos/cpputest/cpputest/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cpputest/cpputest/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cpputest/cpputest/git/refs{/sha}","trees_url":"https://api.github.com/repos/cpputest/cpputest/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cpputest/cpputest/statuses/{sha}","languages_url":"https://api.github.com/repos/cpputest/cpputest/languages","stargazers_url":"https://api.github.com/repos/cpputest/cpputest/stargazers","contributors_url":"https://api.github.com/repos/cpputest/cpputest/contributors","subscribers_url":"https://api.github.com/repos/cpputest/cpputest/subscribers","subscription_url":"https://api.github.com/repos/cpputest/cpputest/subscription","commits_url":"https://api.github.com/repos/cpputest/cpputest/commits{/sha}","git_commits_url":"https://api.github.com/repos/cpputest/cpputest/git/commits{/sha}","comments_url":"https://api.github.com/repos/cpputest/cpputest/comments{/number}","issue_comment_url":"https://api.github.com/repos/cpputest/cpputest/issues/comments{/number}","contents_url":"https://api.github.com/repos/cpputest/cpputest/contents/{+path}","compare_url":"https://api.github.com/repos/cpputest/cpputest/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cpputest/cpputest/merges","archive_url":"https://api.github.com/repos/cpputest/cpputest/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cpputest/cpputest/downloads","issues_url":"https://api.github.com/repos/cpputest/cpputest/issues{/number}","pulls_url":"https://api.github.com/repos/cpputest/cpputest/pulls{/number}","milestones_url":"https://api.github.com/repos/cpputest/cpputest/milestones{/number}","notifications_url":"https://api.github.com/repos/cpputest/cpputest/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cpputest/cpputest/labels{/name}","releases_url":"https://api.github.com/repos/cpputest/cpputest/releases{/id}","created_at":"2012-08-02T07:32:25Z","updated_at":"2015-08-09T20:34:39Z","pushed_at":"2015-08-10T11:18:25Z","git_url":"git://github.com/cpputest/cpputest.git","ssh_url":"git@github.com:cpputest/cpputest.git","clone_url":"https://github.com/cpputest/cpputest.git","svn_url":"https://github.com/cpputest/cpputest","homepage":"http://cpputest.github.com","size":14444,"stargazers_count":237,"watchers_count":237,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":140,"mirror_url":null,"open_issues_count":105,"forks":140,"open_issues":105,"watchers":237,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cpputest/cpputest/pulls/752"},"html":{"href":"https://github.com/cpputest/cpputest/pull/752"},"issue":{"href":"https://api.github.com/repos/cpputest/cpputest/issues/752"},"comments":{"href":"https://api.github.com/repos/cpputest/cpputest/issues/752/comments"},"review_comments":{"href":"https://api.github.com/repos/cpputest/cpputest/pulls/752/comments"},"review_comment":{"href":"https://api.github.com/repos/cpputest/cpputest/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cpputest/cpputest/pulls/752/commits"},"statuses":{"href":"https://api.github.com/repos/cpputest/cpputest/statuses/d60e0e4b0019f5a54d3cafb09ba30578e86bb2ad"}}}}