Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 51a2e4d5 authored by Colin Cross's avatar Colin Cross Committed by Gerrit Code Review
Browse files

Merge "libsysutils: fix null pointer and memory leak issue"

parents 9246f8d6 544a7f7a
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -112,6 +112,12 @@ char *SocketClient::quoteArg(const char *arg) {
    char *result = (char *)malloc(len * 2 + 3);
    char *current = result;
    const char *end = arg + len;
    char *oldresult;

    if(result == NULL) {
        SLOGW("malloc error (%s)", strerror(errno));
        return NULL;
    }

    *(current++) = '"';
    while (arg < end) {
@@ -125,8 +131,9 @@ char *SocketClient::quoteArg(const char *arg) {
    }
    *(current++) = '"';
    *(current++) = '\0';
    oldresult = result; // save pointer in case realloc fails
    result = (char *)realloc(result, current-result);
    return result;
    return result ? result : oldresult;
}