char *db_subpath = NULL;
char *ret = NULL;
- dir_path = state_path(PERFCOUNTDIR);
+ dir_path = state_path(talloc_tos(), PERFCOUNTDIR);
if (dir_path == NULL) {
return NULL;
}
return NULL;
}
- ret = state_path(db_subpath);
+ ret = state_path(talloc_tos(), db_subpath);
TALLOC_FREE(dir_path);
return ret;
}
uint32_t buffer_size)
{
TDB_DATA kbuf, dbuf;
- char temp[256];
+ char temp[PERFCOUNT_MAX_LEN] = {0};
char *buf1 = *retbuf;
+ char *p = NULL;
uint32_t working_size = 0;
DATA_BLOB name_index, name;
bool ok;
- memset(temp, 0, sizeof(temp));
snprintf(temp, sizeof(temp), "%d", keyval);
kbuf = string_tdb_data(temp);
dbuf = tdb_fetch(tdb, kbuf);
}
/* First encode the name_index */
working_size = (kbuf.dsize + 1)*sizeof(uint16_t);
- buf1 = (char *)SMB_REALLOC(buf1, buffer_size + working_size);
- if(!buf1) {
+ /* SMB_REALLOC frees buf1 on error */
+ p = (char *)SMB_REALLOC(buf1, buffer_size + working_size);
+ if (p == NULL) {
buffer_size = 0;
return buffer_size;
}
+ buf1 = p;
ok = push_reg_sz(talloc_tos(), &name_index, (const char *)kbuf.dptr);
if (!ok) {
+ SAFE_FREE(buf1);
buffer_size = 0;
return buffer_size;
}
buffer_size += working_size;
/* Now encode the actual name */
working_size = (dbuf.dsize + 1)*sizeof(uint16_t);
- buf1 = (char *)SMB_REALLOC(buf1, buffer_size + working_size);
- if(!buf1) {
+ /* SMB_REALLOC frees buf1 on error */
+ p = (char *)SMB_REALLOC(buf1, buffer_size + working_size);
+ if (p == NULL) {
buffer_size = 0;
return buffer_size;
}
+ buf1 = p;
memset(temp, 0, sizeof(temp));
memcpy(temp, dbuf.dptr, dbuf.dsize);
SAFE_FREE(dbuf.dptr);
ok = push_reg_sz(talloc_tos(), &name, temp);
if (!ok) {
+ SAFE_FREE(buf1);
buffer_size = 0;
return buffer_size;
}
TDB_CONTEXT *names)
{
TDB_DATA key, data;
- char buf[PERFCOUNT_MAX_LEN], temp[PERFCOUNT_MAX_LEN];
+ char buf[PERFCOUNT_MAX_LEN] = {0};
+ char temp[32] = {0};
smb_ucs2_t *name = NULL;
int pad;
/* First grab the instance data from the data file */
- memset(temp, 0, PERFCOUNT_MAX_LEN);
- snprintf(temp, PERFCOUNT_MAX_LEN, "i%d", instId);
+ snprintf(temp, sizeof(temp), "i%d", instId);
_reg_perfcount_make_key(&key, buf, PERFCOUNT_MAX_LEN, obj->ObjectNameTitleIndex, temp);
if (!_reg_perfcount_get_counter_data(key, &data)) {
DEBUG(3, ("_reg_perfcount_get_counter_data failed\n"));
SAFE_FREE(data.dptr);
/* Fetch instance name */
- memset(temp, 0, PERFCOUNT_MAX_LEN);
- snprintf(temp, PERFCOUNT_MAX_LEN, "i%dname", instId);
+ snprintf(temp, sizeof(temp), "i%dname", instId);
_reg_perfcount_make_key(&key, buf, PERFCOUNT_MAX_LEN, obj->ObjectNameTitleIndex, temp);
data = tdb_fetch(names, key);
if(data.dptr == NULL)
/* Now do the counters */
/* If no instances, encode counter_data */
- /* If instances, encode instace plus counter data for each instance */
+ /* If instances, encode instance plus counter data for each instance */
if(_reg_perfcount_marshall_perf_counters(ps, object, depth) == False)
return False;
if(object.NumInstances == PERF_NO_INSTANCES)