Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. void get_modeles_names(int mode, char ** modeles)
  2. {
  3. FILE * collection = get_collection_file();
  4. int i = 0;
  5. char * line = NULL;
  6. size_t size = 0;
  7.  
  8. while (getline(&line, &size, collection) != -1) {
  9. if (strstr(line, entete)) {
  10. modeles[i] = (char*) malloc(strlen(line) * sizeof (char));
  11. modeles[i] = line;
  12.  
  13. modeles[i][strlen(modeles[i]) - 1] = '';
  14. //replaces the final 'n' by ''
  15.  
  16. i++;
  17. line = NULL;
  18. }
  19. }
  20.  
  21. if (line)
  22. free(line);
  23.  
  24. fclose(collection);
  25. }
  26.  
  27. void det_langue(char * w)
  28. {
  29. int nb_modele = nb_modeles();
  30.  
  31. char ** modeles = (char **) malloc(nb_modele * sizeof (char *));
  32. get_modeles_names(mode, modeles);
  33.  
  34. double * resultats = (double *) malloc(nb_modele * sizeof (double));
  35.  
  36. int i;
  37. for (i = 0; i < nb_modele; i++) {
  38. resultats[i] = calculate_result (w, modeles[i]);
  39. }
  40. }
  41.  
  42. for (i = 0; i < nb_modele; i++) {
  43. free(modeles[i]);
  44. }
  45. free(modeles);
  46. free(resultats);
  47. }
  48.  
  49. ==30547== Command: ./projet -d pomme -m 1
  50. ==30547==
  51. pomme -> french
  52. ==30547==
  53. ==30547== HEAP SUMMARY:
  54. ==30547== in use at exit: 113 bytes in 4 blocks
  55. ==30547== total heap usage: 40 allocs, 36 frees, 30,906 bytes allocated
  56. ==30547==
  57. ==30547== 113 bytes in 4 blocks are definitely lost in loss record 1 of 1
  58. ==30547== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
  59. ==30547== by 0x40163E: get_modeles_names (gestion_collection_modeles.c:120)
  60. ==30547== by 0x401919: det_langue (det_langue.c:12)
  61. ==30547== by 0x40189E: main (Main.c:76)
  62. ==30547==
  63. ==30547== LEAK SUMMARY:
  64. ==30547== definitely lost: 113 bytes in 4 blocks
  65. ==30547== indirectly lost: 0 bytes in 0 blocks
  66. ==30547== possibly lost: 0 bytes in 0 blocks
  67. ==30547== still reachable: 0 bytes in 0 blocks
  68. ==30547== suppressed: 0 bytes in 0 blocks
  69. ==30547==
  70. ==30547== For counts of detected and suppressed errors, rerun with: -v
  71. ==30547== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement