'Macos get pointer being realloc'd was not allocated error in gas assembly

I am writing a simple compiler for gas assembly on macos which generated this assembly:

    .section __TEXT, __text
    .globl _print
_print:
    pushq %rbp
    movq %rsp, %rbp
    movb $0, %al
    call _printf
    xorl %eax, %eax
    popq %rbp
    retq
str0:
    .asciz ""
    .globl _main
_main:
    pushq %rbp
    movq %rsp, %rbp
    leaq str0(%rip), %rax
    movq %rax, 0(%rbp)
    movq ___stdinp@GOTPCREL(%rip), %rax
    movq $0, 1(%rbp)
    movq (%rax), %rdx
    leaq 2(%rbp), %rdi
    leaq 1(%rbp), %rsi
    callq _getline
    movq 0(%rbp), %rsi
    movq 0(%rbp), %rdi
    callq _print
    xorl %eax, %eax
    popq %rbp
    retq
.subsections_via_symbols

And run it using:

gcc -c main.s -o main.o gcc main.o -o main ./main

But whenever I use ./main I get: main(13366,0x1132f8e00) malloc: *** error for object 0x5f00000000000000: pointer being realloc'd was not allocated main(13366,0x1132f8e00) malloc: *** set a breakpoint in malloc_error_break to debug

I don't know what I could do to fix this and have no idea what is going wrong so any help would be appreciated!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source