You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

simple_mem_leak.c 658 B

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <memory.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. int uadd_ok(unsigned short x, unsigned short y);
  5. int main(void) {
  6. int* i_ptr = malloc(sizeof(int));
  7. if (i_ptr) {
  8. (void)printf("malloc() success...\n");
  9. // mem leak
  10. }
  11. unsigned short x1 =65530;
  12. int re = uadd_ok(x1,200);
  13. return re;
  14. }
  15. int func(void) {
  16. int* i_ptr = malloc(sizeof(int));
  17. if (i_ptr) {
  18. (void)printf("malloc() success...\n");
  19. // mem leak
  20. }
  21. }
  22. int uadd_ok(unsigned short x, unsigned short y){
  23. unsigned short sum =x+y;
  24. char c1;
  25. char c2 = -128;
  26. c1=~c2; //error
  27. if(sum >=x) {
  28. return 1;
  29. }
  30. if (c1 > 0) return 0;
  31. }

No Description

Contributors (1)