42shpimanmls / 42sh

Shell project at 42
3 stars 0 forks source link

Leaks #134

Closed M5oul closed 7 years ago

n0izn0iz commented 7 years ago

Leaks, read error? logs?

M5oul commented 7 years ago

Leaks, for instance with valgrind --leak-check=full ./42sh:

$ toto
>42sh: toto: no such command.
==11101== 
==11101== HEAP SUMMARY:
==11101==     in use at exit: 21,195 bytes in 239 blocks
==11101==   total heap usage: 2,899 allocs, 2,660 frees, 161,341 bytes allocated
==11101== 
==11101== 48 bytes in 3 blocks are definitely lost in loss record 15 of 36
==11101==    at 0x4C2DB9D: malloc (vg_replace_malloc.c:299)
==11101==    by 0x40EAAD: memalloc_or_die (memalloc_or_die.c:7)
==11101==    by 0x403608: add_to_string (editor.c:41)
==11101==    by 0x403A39: add_buffer_to_string (edit_input.c:15)
==11101==    by 0x403958: start_normal_mode (edit_input.c:58)
==11101==    by 0x403896: edit_input (edit_input.c:99)
==11101==    by 0x40299A: handle_stdin (read_input.c:24)
==11101==    by 0x4028E6: read_input (read_input.c:35)
==11101==    by 0x40933C: main_loop (main.c:18)
==11101==    by 0x4092DE: main (main.c:55)
==11101== 
==11101== 1,418 (304 direct, 1,114 indirect) bytes in 1 blocks are definitely lost in loss record 33 of 36
==11101==    at 0x4C2DB9D: malloc (vg_replace_malloc.c:299)
==11101==    by 0x40EAAD: memalloc_or_die (memalloc_or_die.c:7)
==11101==    by 0x40502B: create_envp (get_for_execution.c:59)
==11101==    by 0x404F2A: get_variables_for_execution (get_for_execution.c:95)
==11101==    by 0x405C5E: execute_simple_command (execute_pipeline.c:71)
==11101==    by 0x405D11: execute_pipeline (execute_pipeline.c:95)
==11101==    by 0x406905: execute_and_or_list (execute_command_list.c:36)
==11101==    by 0x406A01: execute_command_list (execute_command_list.c:77)
==11101==    by 0x4093F1: main_loop (main.c:36)
==11101==    by 0x4092DE: main (main.c:55)
==11101== 
==11101== LEAK SUMMARY:
==11101==    definitely lost: 352 bytes in 4 blocks
==11101==    indirectly lost: 1,114 bytes in 37 blocks
==11101==      possibly lost: 0 bytes in 0 blocks
==11101==    still reachable: 19,729 bytes in 198 blocks
==11101==         suppressed: 0 bytes in 0 blocks
==11101== Reachable blocks (those to which a pointer was found) are not shown.
==11101== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==11101== 
==11101== For counts of detected and suppressed errors, rerun with: -v
==11101== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
pilespin commented 7 years ago

get_variables_for_execution il est pas freetabchar a certain moment

M5oul commented 7 years ago

Just starting the shell on master branch, and getting leaks status with leaks:

leaks 42sh
Process:         42sh [92189]
Path:            /Users/mazimi/projects/42sh/42sh
Load Address:    0x107d40000
Identifier:      42sh
Version:         ???
Code Type:       X86-64
Parent Process:  zsh [49909]

Date/Time:       2017-04-14 10:17:08.333 +0200
Launch Time:     2017-04-14 10:17:06.891 +0200
OS Version:      Mac OS X 10.12.1 (16B2657)
Report Version:  7
Analysis Tool:   /Applications/Xcode.app/Contents/Developer/usr/bin/leaks
Analysis Tool Version:  Xcode 8.2.1 (8C1002)
----

leaks Report Version:  2.0
Process 92189: 262 nodes malloced for 27 KB
Process 92189: 1 leak for 4096 total leaked bytes.
Leak: 0x7f91f4003200  size=4096  zone: DefaultMallocZone_0x107d6b000
    0x00000000 0x00000000 0x00000000 0x00000000     ................
    0x00000000 0x00000000 0x00000000 0x00000000     ................
    0x00000000 0x00000000 0x00000000 0x00000000     ................
    0x00000000 0x00000000 0x00000000 0x00000000     ................
    0x00000000 0x00000000 0x00000000 0x00000000     ................
    0x00000000 0x00000000 0x00000000 0x00000000     ................
    0x00000000 0x00000000 0x00000000 0x00000000     ................
    0x00000000 0x00000000 0x00000000 0x00000000     ................
    ...
M5oul commented 7 years ago

Each time I run a cmd there is two following leaks added:

Leak: 0x7f91f3e00100  size=16  zone: DefaultMallocZone_0x107d6b000  length: 1  "0"
eak: 0x7f91f4003200  size=4096  zone: DefaultMallocZone_0x107d6b000
    0x00000000 0x00000000 0x00000000 0x00000000     ................
    0x00000000 0x00000000 0x00000000 0x00000000     ................
    0x00000000 0x00000000 0x00000000 0x00000000     ................
    0x00000000 0x00000000 0x00000000 0x00000000     ................
    0x00000000 0x00000000 0x00000000 0x00000000     ................
    0x00000000 0x00000000 0x00000000 0x00000000     ................
    0x00000000 0x00000000 0x00000000 0x00000000     ................
    0x00000000 0x00000000 0x00000000 0x00000000     ................
    ...
n0izn0iz commented 7 years ago

go hunt les leaks avec valgrind, ya aucun moyen de savoir d’où ça viens a part le contenu des données avec leaks.

pilespin commented 7 years ago

ONE HUNTED

n0izn0iz commented 7 years ago

Hunter leaKS Hunter

pilespin commented 7 years ago

TWO

pilespin commented 7 years ago

THREE

pilespin commented 7 years ago

envp il est pas free quand command not found

lsimonne commented 7 years ago

j'crois qu'il y en a quelques-uns dans les substitutions d'historique aussi, je m'en chargerai en retestant tout ça

M5oul commented 7 years ago

I see only three places where this could leaks:

grep -rn "= get_variables_for_execution" | grep -v binair
execution/exec.c:22:    env = get_variables_for_execution(cmd->assignments);
execution/execute_pipeline.c:71:        environ = get_variables_for_execution(cmd->assignments);
expansion/command_substitution.c:76:    environ = get_variables_for_execution(NULL);

Memory management seems ok. I don't know how to fix this.

lsimonne commented 7 years ago

suffit de supprimer environ et environ_backup complètement dans execute_simple_command, ils n'étaient utiles que quand on utilisait execvp, non?