Advertisement
0xLeon

ZDK04 Memory Leak Demo Code

Aug 11th, 2015
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "cab202_graphics.h"
  4. #include "cab202_sprites.h"
  5.  
  6. #define SPRITE_X    200
  7. #define SPRITE_Y    200
  8.  
  9. sprite_id get_sprite() {
  10.     int char_count = SPRITE_X * SPRITE_Y;
  11.     char* buffer = malloc(char_count * sizeof(char));
  12.    
  13.     if (buffer == NULL) {
  14.         printf("%s", "No memory!");
  15.        
  16.         abort();
  17.     }
  18.    
  19.     for (int a = 0; a < char_count; a++) {
  20.         buffer[a] = ((a % 2) == 0) ? '-' : '|';
  21.     }
  22.    
  23.     return create_sprite(0, 0, SPRITE_X, SPRITE_Y, buffer);
  24. }
  25.  
  26. int main() {
  27.     sprite_id sprite = NULL;
  28.    
  29.     setup_screen();
  30.     clear_screen();
  31.    
  32.     for (int i = 0; i < 100000; i++) {
  33.         sprite = get_sprite();
  34.         destroy_sprite(sprite);
  35.     }
  36.    
  37.     draw_string(0, 0, "Press any key to exit...");
  38.     show_screen();
  39.    
  40.     wait_char();
  41.    
  42.     cleanup_screen();
  43.    
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement