hawq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ztao1987 <...@git.apache.org>
Subject [GitHub] incubator-hawq pull request: HAWQ-644. Account for '\0' when dispa...
Date Fri, 15 Apr 2016 02:19:14 GMT
Github user ztao1987 commented on a diff in the pull request:

    --- Diff: src/backend/cdb/cdbquerycontextdispatching.c ---
    @@ -779,21 +779,24 @@ static void
     RebuildNamespace(QueryContextInfo *cxt)
    +	MemoryContext oldContext;
     	int len;
     	char buffer[4], *binary;
    +	oldContext = MemoryContextSwitchTo(MessageContext);
     	ReadData(cxt, buffer, sizeof(buffer), TRUE);
     	len = (int) ntohl(*(uint32 *) buffer);
     	binary = palloc(len);
     	if(ReadData(cxt, binary, len, TRUE))
    -		StringInfoData buffer;
    -		initStringInfoOfString(&buffer, binary, len);
    -		dfs_address = strdup(buffer.data);
    +		dfs_address = pstrdup(binary);
    --- End diff --
    pstrdup is a kind of malloc, not covered by memorycontext. So there is memory leak in
your code. Why not just use dfs_address directly instead of binary? Also even memorycontext
used, the best practice is to pfree the memory explictly. Memorycontext is the last barrier
which protects the memory.

If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.

View raw message