Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2011
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.13 KB | None | 0 0
  1. /* This program: */
  2.  
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. int main()
  7. {
  8.         char str[] = "MYVAR=Example";
  9.         char *mem = malloc(sizeof(str));
  10.         strcpy(mem, str);
  11.         putenv(mem);
  12. }
  13.  
  14. /* Produced output:
  15.  
  16. ==4219== Memcheck, a memory error detector
  17. ==4219== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
  18. ==4219== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info
  19. ==4219== Command: ./a.out
  20. ==4219==
  21. ==4219==
  22. ==4219== HEAP SUMMARY:
  23. ==4219==     in use at exit: 14 bytes in 1 blocks
  24. ==4219==   total heap usage: 2 allocs, 1 frees, 194 bytes allocated
  25. ==4219==
  26. ==4219== LEAK SUMMARY:
  27. ==4219==    definitely lost: 14 bytes in 1 blocks
  28. ==4219==    indirectly lost: 0 bytes in 0 blocks
  29. ==4219==      possibly lost: 0 bytes in 0 blocks
  30. ==4219==    still reachable: 0 bytes in 0 blocks
  31. ==4219==         suppressed: 0 bytes in 0 blocks
  32. ==4219== Rerun with --leak-check=full to see details of leaked memory
  33. ==4219==
  34. ==4219== For counts of detected and suppressed errors, rerun with: -v
  35. ==4219== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 13 from 8)
  36. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement