Check-in [56c0612e71]
Overview
Comment:Corrected memory leaks in CVFS
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:56c0612e71661df93ce12b73247697c8e78bc55a
User & Date: rkeene on 2014-11-14 21:43:47
Other Links: manifest | tags
Context
2014-11-17
18:43
Updated order of Incr/Decr in CVFS for consistency check-in: dfa8940a62 user: rkeene tags: trunk
2014-11-14
21:43
Corrected memory leaks in CVFS check-in: 56c0612e71 user: rkeene tags: trunk
2014-11-13
18:03
Updated 8.6 builds to 8.6.3 check-in: 02c667ab97 user: rkeene tags: trunk
Changes

Modified kitsh/buildsrc/kitsh-0.0/cvfs_data.c from [dcf0f1a5fd] to [2f0d8b57ce].

    16     16   	cmd_getData_t *cmd_getData;
    17     17   	cmd_getChildren_t *cmd_getChildren;
    18     18   	struct cvfs_data *finfo = NULL;
    19     19   	Tcl_Obj *ret_list, *ret_list_items[20];
    20     20   	unsigned long num_children;
    21     21   	const char *hashkey;
    22     22   	const char *file;
           23  +	int idx;
    23     24   
    24     25   	if (objc != 3) {
    25     26   		Tcl_SetResult(interp, "wrong # args: should be \"getMetadata hashKey fileName\"", TCL_STATIC);
    26     27   
    27     28   		return(TCL_ERROR);
    28     29   	}
    29     30   
................................................................................
    81     82   	ret_list_items[15] = Tcl_NewStringObj("0", 1);
    82     83   
    83     84   	ret_list_items[16] = Tcl_NewStringObj("mtime", 5);
    84     85   	ret_list_items[17] = Tcl_NewStringObj("0", 1);
    85     86   
    86     87   	ret_list_items[18] = Tcl_NewStringObj("ctime", 5);
    87     88   	ret_list_items[19] = Tcl_NewStringObj("0", 1);
           89  +
           90  +	for (idx = 0; idx < (sizeof(ret_list_items) / sizeof(ret_list_items[0])); idx++) {
           91  +		Tcl_IncrRefCount(ret_list_items[idx]);
           92  +	}
    88     93   
    89     94   	ret_list = Tcl_NewListObj(sizeof(ret_list_items) / sizeof(ret_list_items[0]), ret_list_items);
           95  +
           96  +	Tcl_IncrRefCount(ret_list);
           97  +
           98  +	for (idx = 0; idx < (sizeof(ret_list_items) / sizeof(ret_list_items[0])); idx++) {
           99  +		Tcl_DecrRefCount(ret_list_items[idx]);
          100  +	}
    90    101   
    91    102   	Tcl_SetObjResult(interp, ret_list);
          103  +
          104  +	Tcl_DecrRefCount(ret_list);
    92    105   
    93    106   	return(TCL_OK);
    94    107   }
    95    108   
    96    109   static int getData(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
    97    110   	struct cvfs_data *finfo = NULL;
    98    111   	cmd_getData_t *cmd_getData;
................................................................................
   175    188   	if (end < start) {
   176    189   		Tcl_SetResult(interp, "Invalid arguments, start must be less than end", TCL_STATIC);
   177    190   
   178    191   		return(TCL_ERROR);
   179    192   	}
   180    193   
   181    194   	ret_str = Tcl_NewByteArrayObj(finfo->data + start, (end - start));
          195  +
          196  +	Tcl_IncrRefCount(ret_str);
   182    197   
   183    198   	Tcl_SetObjResult(interp, ret_str);
          199  +
          200  +	Tcl_DecrRefCount(ret_str);
   184    201   
   185    202   	return(TCL_OK);
   186    203   }
   187    204   
   188    205   static int getChildren(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
   189    206   	struct cvfs_data *finfo = NULL;
   190    207   	cmd_getChildren_t *cmd_getChildren;
................................................................................
   239    256   
   240    257   	ret_list = Tcl_NewObj();
   241    258   	if (ret_list == NULL) {
   242    259   		Tcl_SetResult(interp, "Failed to allocate new object", TCL_STATIC);
   243    260   
   244    261   		return(TCL_ERROR);
   245    262   	}
          263  +
          264  +	Tcl_IncrRefCount(ret_list);
   246    265   
   247    266   	children = malloc(sizeof(*children) * num_children);
   248    267   
   249    268   	num_children = cmd_getChildren(file, children, num_children);
   250    269   
   251    270   	for (idx = 0; idx < num_children; idx++) {
   252    271   		finfo = cmd_getData(NULL, children[idx]);
................................................................................
   254    273   		if (finfo == NULL || finfo->name == NULL) {
   255    274   			continue;
   256    275   		}
   257    276   
   258    277   		child = finfo->name;
   259    278   
   260    279   		ret_curr_obj = Tcl_NewStringObj(child, strlen(child));
          280  +
          281  +		Tcl_IncrRefCount(ret_curr_obj);
   261    282   
   262    283   		Tcl_ListObjAppendList(interp, ret_list, ret_curr_obj);
          284  +
          285  +		Tcl_DecrRefCount(ret_curr_obj);
   263    286   	}
   264    287   
   265    288   	free(children);
   266    289   
   267    290   	Tcl_SetObjResult(interp, ret_list);
          291  +
          292  +	Tcl_DecrRefCount(ret_list);
   268    293   
   269    294   	return(TCL_OK);
   270    295   }