Skip to content

Discussion: Allocating and Freeing tempReq  #1

@aadarsh-nagrath

Description

@aadarsh-nagrath

In the thread_fn function, you allocate memory for tempReq using malloc, but you never free it. you can add free(tempReq) before returning from the function to ensure that memory allocated for tempReq is released when no longer needed.

    char *tempReq = (char*)malloc(strlen(buffer) * sizeof(char) + 1);
    // Copy buffer content to tempReq
    for (int i = 0; i < strlen(buffer); i++) {
        tempReq[i] = buffer[i];
    }
    tempReq[strlen(buffer)] = '\0'; // Null-terminate the string

    // Handle request, cache operations, etc.

    // Free dynamically allocated memory for tempReq
    free(tempReq);

    // Close socket and perform other cleanup

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions