~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/hello_malloc.cpp

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include<stdio.h>
 
2
#include<stdlib.h>
 
3
#include<assert.h>
 
4
 
 
5
int main() {
 
6
  // Check that a real malloc is used by allocating, freeing, then seeing that we did actually free by a new allocation going to the original place
 
7
  int N = 100;
 
8
  void *allocs[N];
 
9
  for (int i = 0; i < N; i++)
 
10
    allocs[i] = malloc((i+1)*1024);
 
11
  for (int i = 0; i < N; i++)
 
12
    free(allocs[i]);
 
13
  void *another = malloc(1024);
 
14
  assert(another == allocs[0]);
 
15
  printf("hello, world!\n");
 
16
  return 1;
 
17
}
 
18