hawq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From huor <...@git.apache.org>
Subject [GitHub] incubator-hawq pull request: HAWQ-86. Fix and re-enable unit test ...
Date Fri, 30 Oct 2015 12:23:58 GMT
Github user huor commented on a diff in the pull request:

    https://github.com/apache/incubator-hawq/pull/64#discussion_r43496179
  
    --- Diff: src/backend/access/external/test/hd_work_mgr_mock.c ---
    @@ -51,3 +51,49 @@ void restoreCdbComponentDatabases()
     	GpAliveSegmentsInfo.cdbComponentDatabases = orig_cdb;
     	GpAliveSegmentsInfo.aliveSegmentsCount = orig_seg_count;
     }
    +
    +/* Builds the QueryResource for a query */
    +void buildQueryResource(int segs_num,
    +                        char * segs_hostips[])
    +{
    +	resource = (QueryResource *)palloc(sizeof(QueryResource));
    +
    +	resource->segments = NULL;
    +	for (int i = 0; i < segs_num; ++i)
    +	{
    +		Segment *segment = (Segment *)palloc0(sizeof(Segment));
    +		segment->hostip = pstrdup(segs_hostips[i]);
    +		segment->segindex = i;
    +		segment->alive = true;
    +
    +		resource->segments = lappend(resource->segments, segment);
    +	}
    +
    +	return resource;
    +}
    +
    +/* Restores the QueryResource for a query */
    +void restoreQueryResource()
    +{
    +	if (resource)
    +	{
    +		ListCell *cell;
    +
    +		if (resource->segments)
    +		{
    +			cell = list_head(resource->segments);
    +			while(cell != NULL)
    +			{
    +				ListCell *tmp = cell;
    +				cell = lnext(cell);
    +
    +				pfree(((Segment *)lfirst(tmp))->hostip);
    +				pfree(lfirst(tmp));
    +				pfree(tmp);
    +			}
    +		}
    +
    +		pfree(resource);
    --- End diff --
    
    Right. It is a good practice to set resource to NULL since it is a global variable. This
will prevent it becomes a dangling pointer.


---
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.
---

Mime
View raw message