Skip to content

Commit

Permalink
terminate strings and free allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
Aakash Arayambeth committed Feb 22, 2025
1 parent 3bce474 commit af37116
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
19 changes: 19 additions & 0 deletions db/views_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -2065,6 +2065,25 @@ hash_view_t *hash_deserialize_view(const char *view_str, struct errstat *err)
}

view = create_hash_view(viewname, tablename, num_keys, keynames, num_partitions, dbnames, err);

if (dbnames) {
for(int i=0;i<num_partitions;i++){
if (dbnames[i]) {
free(dbnames[i]);
}
}
free(dbnames);
}


if (keynames) {
for(int i=0;i<num_keys;i++){
if (keynames[i]) {
free(keynames[i]);
}
}
free(keynames);
}
if (rootVal) {
cson_value_free(rootVal);
}
Expand Down
22 changes: 22 additions & 0 deletions schemachange/sc_struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,33 @@ void free_schema_change_type(struct schema_change_type *s)
Pthread_cond_destroy(&s->condStart);
Pthread_mutex_destroy(&s->mtxStart);

/*if (s->partition.type == PARTITION_ADD_COL_HASH) {
char *str = s->partition.u.hash.viewname;
if (str) free(str);
for(int i=0;i<s->partition.u.hash.num_columns;i++){
str = s->partition.u.hash.columns[i];
if (str) free(str);
}
if (s->partition.u.hash.columns) {
free(s->partition.u.hash.columns);
}
for(int i=0;i<s->partition.u.hash.num_partitions;i++){
str = s->partition.u.hash.partitions[i];
if (str) free(str);
}
if (s->partition.u.hash.partitions) {
free(s->partition.u.hash.partitions);
}
}*/

if (s->sb && s->must_close_sb) {
close_appsock(s->sb);
s->sb = NULL;
}
if (!s->onstack) {
free(s);
}

}

static size_t dests_field_packed_size(struct schema_change_type *s)
Expand Down Expand Up @@ -1072,6 +1092,7 @@ void *buf_get_schemachange_v2(struct schema_change_type *s,
s->partition.u.hash.columns[i] = (char *)malloc(sizeof(char) * len + 1);
p_buf = (uint8_t *)buf_no_net_get(s->partition.u.hash.columns[i], len,
p_buf, p_buf_end);
s->partition.u.hash.columns[i][len]='\0';
logmsg(LOGMSG_USER, "GOT COLUMN AS %s \n", s->partition.u.hash.columns[i]);
}
p_buf =
Expand All @@ -1083,6 +1104,7 @@ void *buf_get_schemachange_v2(struct schema_change_type *s,
s->partition.u.hash.partitions[i] = (char *)malloc(sizeof(char) * len + 1);
p_buf = (uint8_t *)buf_no_net_get(s->partition.u.hash.partitions[i], len, p_buf,
p_buf_end);
s->partition.u.hash.partitions[i][len]='\0';
logmsg(LOGMSG_USER, "GOT PARTITION AS %s \n", s->partition.u.hash.partitions[i]);
}
break;
Expand Down
33 changes: 32 additions & 1 deletion sqlite/src/comdb2build.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ int createRemotePartitions(struct comdb2_partition *partition);
int createLocalAliases(struct comdb2_partition *partition);
void deleteRemoteTables(const char *, char **, int startIdx);
void deleteRemotePartitions(const char *, char **, int startIdx);
void free_comdb2_partition(struct comdb2_partition *partition);
/******************* Utility ****************************/

static inline int setError(Parse *pParse, int rc, const char *msg)
Expand Down Expand Up @@ -599,6 +600,8 @@ static int comdb2SqlSchemaChange_int(OpFunc *f, int usedb)
f->errorMsg = "Transactional DDL Error: Overlapping Tables";
else if (f->rc)
f->errorMsg = "Transactional DDL Error: Internal Errors";

free_comdb2_partition(&(s->partition));
return f->rc;
}

Expand Down Expand Up @@ -7794,6 +7797,34 @@ static int comdb2GetHashPartitionParams(Parse* pParse, IdList *pColumn, IdList *
return 0;
}

void free_comdb2_partition(struct comdb2_partition *partition) {

if (partition) {
if (partition->u.hash.viewname) {
free(partition->u.hash.viewname);
}
if (partition->u.hash.columns) {
for(int i=0;i<partition->u.hash.num_columns;i++){
if (partition->u.hash.columns[i]) {
free(partition->u.hash.columns[i]);
}
}
free(partition->u.hash.columns);
}
if (partition->u.hash.partitions) {
for(int i=0;i<partition->u.hash.num_partitions;i++){
if (partition->u.hash.partitions[i]) {
free(partition->u.hash.partitions[i]);
}
}
free(partition->u.hash.partitions);
}

if (partition->u.hash.createQuery) {
free(partition->u.hash.createQuery);
}
}
}
struct comdb2_partition *_get_comdb2_hash_partition(Parse *pParse, IdList *pColumn, IdList *pPartitions, int remove) {
struct comdb2_partition *partition;
partition = _get_partition(pParse, 0);
Expand Down Expand Up @@ -7865,7 +7896,7 @@ void comdb2CreateHashPartition(Parse *pParse, IdList *pColumn, IdList *pPartitio
GET_CLNT;
if (clnt && clnt->sql) {
logmsg(LOGMSG_USER, "The sql query is %s\n", clnt->sql);
partition->u.hash.createQuery = clnt->sql;
partition->u.hash.createQuery = strdup(clnt->sql);
} else {
if (!clnt) {
logmsg(LOGMSG_USER, "The client object is not available\n");
Expand Down

0 comments on commit af37116

Please sign in to comment.