A computer implemented method of adjusting code files to apply dynamic memory protection, comprising: receiving at least one code file comprising a plurality of routines, the at least one code file was created for execution by at least one processor using a dynamic memory region supporting run-time dynamic allocation of memory blocks; analyzing the at least one code file to identify at least one exploitation vulnerable routine of the plurality of routines, and adjusting the at least one code file to include an allocation tracking code segment configured to maintain at least one recent allocation list to track, in runtime, a subset comprising a limited number of most recently allocated blocks of a plurality of blocks dynamically allocated in the dynamic memory region used by the at least one processor executing the at least one adjusted code file, each of the most recently allocated blocks is associated in the at least one recent allocation list with a pointer to the respective most recently allocated block, a respective one of a plurality of markers inserted in the dynamic memory region in at least one boundary of the respective most recently allocated block and a size of the respective most recently allocated block; wherein the adjusting further includes adjusting the at least one code file to include a memory integrity code segment invoked upon execution completion of the at least one exploitation vulnerable routine, the memory integrity code segment is configured to detect a write operation exceeding from a memory space of at least one most recently allocated block of the subset of most recently allocated blocks to a memory space of at least one of the plurality of blocks adjacent to the at least one most recently allocated block, the exceeding write operation is detected using at least one of the plurality of markers, the memory integrity code segment identifies the subset of most recently allocated blocks by traversing the at least one recent allocation list; and outputting the at least one adjusted code file; wherein, in runtime, in case the exceeding write operation is detected, the memory integrity code segment causes the at least one processor to initiate at least one predefined action. receiving at least one code file comprising a plurality of routines, the at least one code file was created for execution by at least one processor using a dynamic memory region supporting run-time dynamic allocation of memory blocks; analyzing the at least one code file to identify at least one exploitation vulnerable routine of the plurality of routines, and adjusting the at least one code file to include an allocation tracking code segment configured to maintain at least one recent allocation list to track, in runtime, a subset comprising a limited number of most recently allocated blocks of a plurality of blocks dynamically allocated in the dynamic memory region used by the at least one processor executing the at least one adjusted code file, each of the most recently allocated blocks is associated in the at least one recent allocation list with a pointer to the respective most recently allocated block, a respective one of a plurality of markers inserted in the dynamic memory region in at least one boundary of the respective most recently allocated block and a size of the respective most recently allocated block; wherein the adjusting further includes adjusting the at least one code file to include a memory integrity code segment invoked upon execution completion of the at least one exploitation vulnerable routine, the memory integrity code segment is configured to detect a write operation exceeding from a memory space of at least one most recently allocated block of the subset of most recently allocated blocks to a memory space of at least one of the plurality of blocks adjacent to the at least one most recently allocated block, the exceeding write operation is detected using at least one of the plurality of markers, the memory integrity code segment identifies the subset of most recently allocated blocks by traversing the at least one recent allocation list; and outputting the at least one adjusted code file; wherein, in runtime, in case the exceeding write operation is detected, the memory integrity code segment causes the at least one processor to initiate at least one predefined action.