C - Binary to Decimal segmentation error : I am using a pointer in place of an array, I'm aware that a pointer needs to be freed unlike an array. Why is it that using a pointer in place of an array gives me a segmentation memory error.

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <math.h>

    void bin(void){

	char *input;
	int choice;
	int x = 0;

	
		printf("Enter Decimal Code:\n");
		scanf("%s",&input);

		int leng = strlen(input);



		for(int i = 0; i <= leng ; ++i){

			if(input[i] == '1'){
				x += pow(2,i);
				
				
			}
			else if(input[i] == '0'){
				input[i] = 0;
				

			}
			free(input);

		}
			printf("Binary-Dec: %d\n",x);

		
	}
	
    int main()
    {
	bin();

    }

	
