Skip to content

Commit

Permalink
Merge pull request #20 from jfsmig/upstream-release-0.6
Browse files Browse the repository at this point in the history
Fixed memory leaks.
  • Loading branch information
jfsmig committed May 15, 2015
2 parents 1ecbe06 + f0a45a0 commit 8d33574
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 69 deletions.
12 changes: 7 additions & 5 deletions cluster/remote/gridcluster_remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,16 @@ gcluster_get_services(const char *target, gdouble timeout,
const gchar *type, gboolean full, GError ** error)
{
struct message_s *req = message_create_named(NAME_MSGNAME_CS_GET_SRV);
message_add_fields_str (req,
NAME_MSGKEY_TYPENAME, type,
NAME_MSGKEY_FULL, full?"1":NULL,
NULL);
message_add_field (req, NAME_MSGKEY_TYPENAME, type, strlen(type));
if (full)
message_add_field_struint (req, NAME_MSGKEY_FULL, 1);
GByteArray *gba = message_marshall_gba_and_clean(req);

GSList *out = NULL;
GError *err = gridd_client_exec_and_decode (target, timeout,
message_marshall_gba_and_clean(req), &out, service_info_unmarshall);
gba, &out, service_info_unmarshall);
g_byte_array_unref(gba);

if (err) {
if (error)
g_error_transmit(error, err);
Expand Down
62 changes: 23 additions & 39 deletions meta1v2/meta1_backend_services.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,6 @@ meta1_url_dup(struct meta1_service_url_s *u)
return result;
}

static void
free_urlv(struct meta1_service_url_s **uv)
{
struct meta1_service_url_s **p;

if (!uv)
return;

for (p=uv; *p ;p++) {
if (*p)
g_free(*p);
}

g_free(uv);
}

static gint
urlv_get_max_seq(struct meta1_service_url_s **uv)
{
Expand Down Expand Up @@ -183,8 +167,7 @@ convert_url_to_serviceinfo(struct meta1_service_url_s *u, const gchar *excludeur
}

g_ptr_array_add(tmp, NULL);
if ( extracted )
free_urlv(extracted);
meta1_service_url_cleanv(extracted);
return (struct service_info_s**)g_ptr_array_free(tmp, FALSE);
}

Expand All @@ -197,23 +180,23 @@ __del_container_srvtype_properties(struct sqlx_sqlite3_s *sq3,
GError *err = NULL;
gint rc;
sqlite3_stmt *stmt = NULL;
gchar* tmp_name = NULL;

sqlite3_prepare_debug(rc, sq3->db,
"DELETE FROM properties WHERE cid = ? AND name LIKE ?", -1, &stmt, NULL);
if (rc != SQLITE_OK && rc != SQLITE_DONE)
err = M1_SQLITE_GERROR(sq3->db, rc);
else {
int len = strlen(srvtype)+10;
tmp_name = g_malloc0(sizeof(gchar)*len);
if (tmp_name) {
gchar *tmp_name = g_malloc0(sizeof(gchar)*len);
if (tmp_name) {
g_snprintf(tmp_name, len, "%s.%%", srvtype);
(void) sqlite3_bind_blob(stmt, 1, cid, sizeof(container_id_t), NULL);
(void) sqlite3_bind_text(stmt, 2, tmp_name, strlen(tmp_name), NULL);
do { rc = sqlite3_step(stmt); } while (rc == SQLITE_ROW);
if (rc != SQLITE_OK && rc != SQLITE_DONE)
err = M1_SQLITE_GERROR(sq3->db, rc);
do { rc = sqlite3_step(stmt); } while (rc == SQLITE_ROW);
if (rc != SQLITE_OK && rc != SQLITE_DONE)
err = M1_SQLITE_GERROR(sq3->db, rc);
sqlite3_finalize_debug(rc, stmt);
g_free (tmp_name);
}
}

Expand Down Expand Up @@ -313,6 +296,8 @@ __del_container_services(struct meta1_backend_s *m1,
__del_container_srvtype_properties(sq3, cid, srvtype);
}
}
meta1_service_url_cleanv (used);

GError *err2 = __notify_services_by_cid(m1, sq3, cid);
if (err2 != NULL) {
gchar buf[128] = {0};
Expand Down Expand Up @@ -705,7 +690,7 @@ __get_services_up(struct meta1_backend_s *m1, struct meta1_service_url_s **src)
g_ptr_array_add(gpa, meta1_url_dup(*pe));
}

free_urlv(extracted);
meta1_service_url_cleanv(extracted);
extracted = NULL;
}

Expand Down Expand Up @@ -756,11 +741,11 @@ __get_container_service2(struct sqlx_sqlite3_s *sq3,
struct meta1_service_url_s **up = __get_services_up(m1, used);
if (up && *up) {
*result = pack_urlv(up);
free_urlv(up);
free_urlv(used);
meta1_service_url_cleanv(up);
meta1_service_url_cleanv(used);
return NULL;
}
free_urlv(up);
meta1_service_url_cleanv(up);
}

/* No service available, poll a new one */
Expand All @@ -774,8 +759,7 @@ __get_container_service2(struct sqlx_sqlite3_s *sq3,
seq = urlv_get_max_seq(used);
seq = (seq<0 ? 1 : seq+1);

if (NULL != (m1_url = __poll_services(m1, replicas, ct, seq,
used, &err))) {
if (NULL != (m1_url = __poll_services(m1, replicas, ct, seq, used, &err))) {
if (!(mode & M1V2_GETSRV_DRYRUN)) {
struct sqlx_repctx_s *repctx = NULL;
err = sqlx_transaction_begin(sq3, &repctx);
Expand All @@ -791,7 +775,7 @@ __get_container_service2(struct sqlx_sqlite3_s *sq3,
if (!err && result) {
struct meta1_service_url_s **unpacked = expand_url(m1_url);
*result = pack_urlv(unpacked);
free_urlv(unpacked);
meta1_service_url_cleanv(unpacked);

GError *err2 = __notify_services(m1, sq3, url);
if (err2 != NULL) {
Expand All @@ -805,7 +789,7 @@ __get_container_service2(struct sqlx_sqlite3_s *sq3,
}
}

free_urlv(used);
meta1_service_url_cleanv(used);
return err;
}

Expand Down Expand Up @@ -947,8 +931,8 @@ meta1_backend_get_all_services(struct meta1_backend_s *m1, const container_id_t
struct meta1_service_url_s **expanded;
expanded = expand_urlv(used);
*result = pack_urlv(expanded);
free_urlv(expanded);
free_urlv(used);
meta1_service_url_cleanv(expanded);
meta1_service_url_cleanv(used);
}

sqlx_repository_unlock_and_close_noerror(sq3);
Expand Down Expand Up @@ -1030,8 +1014,8 @@ meta1_backend_get_container_all_services(struct meta1_backend_s *m1,
struct meta1_service_url_s **expanded;
expanded = expand_urlv(uv);
*result = pack_urlv(expanded);
free_urlv(expanded);
free_urlv(uv);
meta1_service_url_cleanv(expanded);
meta1_service_url_cleanv(uv);
}
}
sqlx_repository_unlock_and_close_noerror(sq3);
Expand Down Expand Up @@ -1376,7 +1360,7 @@ _update_m1_policy(struct meta1_backend_s *m1,
failedend:
if (args)
g_free(args);
free_urlv(m1_srv_url);
meta1_service_url_cleanv(m1_srv_url);

return err;
}
Expand Down Expand Up @@ -1610,8 +1594,8 @@ __notify_services(struct meta1_backend_s *m1,
(const guint32 *)hc_url_get_id(url));

g_string_free(notif, TRUE);
free_urlv(services2);
free_urlv(services);
meta1_service_url_cleanv(services2);
meta1_service_url_cleanv(services);
}
return err;
}
Expand Down
5 changes: 3 additions & 2 deletions metautils/lib/comm_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ write_gba(const void *b, gsize bSize, void *key)
GByteArray*
message_marshall_gba(MESSAGE m, GError **err)
{
GByteArray *result = NULL;
asn_enc_rval_t encRet;

/*sanity check */
Expand All @@ -189,7 +188,7 @@ message_marshall_gba(MESSAGE m, GError **err)

/*try to encode */
guint32 u32 = 0;
result = g_byte_array_sized_new(256);
GByteArray *result = g_byte_array_sized_new(256);
g_byte_array_append(result, (guint8*)&u32, sizeof(u32));
encRet = der_encode(&asn_DEF_Message, m->asnMsg, write_gba, result);

Expand Down Expand Up @@ -752,6 +751,8 @@ message_extract_body_gba(struct message_s *msg, GByteArray **result)
void *b = NULL;
gsize bsize = 0;
GError *err = NULL;

*result = NULL;
if (0 > message_get_BODY(msg, &b, &bsize, &err)) {
g_prefix_error (&err, "Body error: ");
return err;
Expand Down
4 changes: 2 additions & 2 deletions metautils/lib/metatype_m1url.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void meta1_service_url_clean(struct meta1_service_url_s *u);
/**
* @param uv
*/
void meta1_service_url_vclean(struct meta1_service_url_s **uv);
void meta1_service_url_cleanv(struct meta1_service_url_s **uv);

/**
* @param u
Expand All @@ -72,4 +72,4 @@ void meta1_service_url_encode_json (GString *gstr,

/** @} */

#endif /*OIO_SDS__metautils__lib__metatype_m1url_h*/
#endif /*OIO_SDS__metautils__lib__metatype_m1url_h*/
2 changes: 1 addition & 1 deletion metautils/lib/utils_m1url.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ meta1_service_url_clean(struct meta1_service_url_s *u)
}

void
meta1_service_url_vclean(struct meta1_service_url_s **uv)
meta1_service_url_cleanv(struct meta1_service_url_s **uv)
{
struct meta1_service_url_s **p;

Expand Down
3 changes: 2 additions & 1 deletion proxy/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ _gba_request (struct meta1_service_url_s *m1u,
{
gboolean _on_reply (gpointer ctx, struct message_s *reply) {
GByteArray **pgba = ctx;
message_extract_body_gba (reply, pgba);
GError *e = message_extract_body_gba (reply, pgba);
if (e) g_clear_error (&e);
return TRUE;
}

Expand Down
3 changes: 2 additions & 1 deletion proxy/sqlx_actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ _sqlx_action_bodyv (struct req_args_s *args,
{
gboolean _on_reply (gpointer ctx, struct message_s *reply) {
GByteArray **pgba = ctx;
message_extract_body_gba (reply, pgba);
GError *e = message_extract_body_gba (reply, pgba);
if (e) g_clear_error (&e);
return TRUE;
}

Expand Down
5 changes: 2 additions & 3 deletions proxy/transport_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ http_manage_request(struct req_ctx_s *r)

void cleanup(void) {
metautils_str_clean (&msg);
metautils_str_clean (&access);
metautils_str_clean ((gchar**)&body.data);
body.len = 0;
if (headers) {
Expand All @@ -456,9 +457,7 @@ http_manage_request(struct req_ctx_s *r)
void set_status(int c, const gchar *m) {
EXTRA_ASSERT(m != NULL);
code = c;
if (msg)
g_free(msg);
msg = g_strdup(m);
metautils_str_replace (&msg, m);
}

void set_content_type(const gchar *type) {
Expand Down
38 changes: 24 additions & 14 deletions tools/sds-bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
from string import Template
import os, errno

#env.G_DEBUG=fatal_warnings
#env.G_SLICE=debug-blocks

template_flask_gridinit = """
[service.${NS}-flask]
group=${NS},localhost,flask
Expand Down Expand Up @@ -368,14 +371,6 @@
"""

template_gridinit_ns = """
[service.${NS}-gridevents]
group=${NS},localhost,events
on_die=respawn
enabled=false
start_at_boot=false
command=${EXE_PREFIX}-cluster-agent -s SDS,${NS},events--child-evt=${NS} ${CFGDIR}/agent.conf
env.PATH=${PATH}
env.LD_LIBRARY_PATH=${HOME}/.local/lib:${LIBDIR}
[service.${NS}-conscience]
group=${NS},localhost,conscience
Expand All @@ -388,11 +383,11 @@
env.LD_LIBRARY_PATH=${HOME}/.local/lib:${LIBDIR}
[service.${NS}-account-agent]
group=${NS},localhost,account-agent
group=${NS},localhost,events
on_die=respawn
enabled=true
start_at_boot=false
command=${EXE_PREFIX}-account-agent.py ${NS}
command=${EXE_PREFIX}-event-agent ${CFGDIR}/events-agent.conf
env.PATH=${HOME}/.local/bin:${CODEDIR}/bin
env.LD_LIBRARY_PATH=${HOME}/.local/lib:${LIBDIR}
"""
Expand Down Expand Up @@ -426,10 +421,16 @@

template_local_ns = """
[${NS}]
zookeeper=${IP}:2181
${NOZK}zookeeper=${IP}:2181
conscience=${IP}:${PORT_CS}
endpoint=${IP}:${PORT_ENDPOINT}
account-agent=ipc://${RUNDIR}/account-agent.sock
event-agent=ipc://${RUNDIR}/event-agent.sock
"""

template_events_agent = """
[eventagent]
bind_addr = ipc://${RUNDIR}/event-agent.sock
workers = 5
"""

HOME = str(os.environ['HOME'])
Expand Down Expand Up @@ -489,10 +490,10 @@ def getint(v,default):
stgpol = str(options.M2_STGPOL)

if options.NO_META0 is None:
for i in range(1, 1+getint(options.NB_META0,1)):
for i in range(1, 1+getint(options.NB_META0, 1)):
services.append(('meta0', EXE_PREFIX + '-meta0-server', i, next_port()))
if options.NO_META1 is None:
for i in range(1, 1+getint(options.NB_META1,3)):
for i in range(1, 1+getint(options.NB_META1, 3)):
services.append(('meta1', EXE_PREFIX + '-meta1-server', i, next_port()))
if options.NO_META2 is None:
for i in range(1, 1+getint(options.NB_META2, meta2_replicas)):
Expand Down Expand Up @@ -529,6 +530,8 @@ def getint(v,default):
f.write(tpl.safe_substitute(env))
env['PORT_CS'] = port_cs
env['PORT_ENDPOINT'] = port_endpoint
if options.NO_ZOOKEEPER is not None:
env['NOZK'] = '#'
tpl = Template(template_local_ns)
f.write(tpl.safe_substitute(env))

Expand Down Expand Up @@ -608,6 +611,11 @@ def getint(v,default):
tpl = Template(template_account_flask_gridinit)
f.write(tpl.safe_substitute(env))

# Events agent configuration
with open(CFGDIR + '/' + 'events-agent.conf', 'w+') as f:
tpl = Template(template_events_agent)
f.write(tpl.safe_substitute(env))

# Central agent configuration
env['PORT'] = port_agent
with open(CFGDIR + '/'+ 'agent.conf', 'w+') as f:
Expand All @@ -631,6 +639,8 @@ def main ():
action="store", type="string", dest="M2_STGPOL",
help="How many replicas for META2")

parser.add_option("--no-zookeeper", action="store_true", dest="NO_ZOOKEEPER")

parser.add_option("--no-meta0", action="store_true", dest="NO_META0")
parser.add_option("--no-meta1", action="store_true", dest="NO_META1")
parser.add_option("--no-meta2", action="store_true", dest="NO_META2")
Expand Down
2 changes: 1 addition & 1 deletion tools/sds-reset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ done
mkdir -p "$OIO"
( cd "$OIO" && (rm -rf sds.conf sds/{conf,data,run,logs}))

opts="--nb-meta1=$((REPLICATION_DIRECTORY+1)) --nb-meta2=$((REPLICATION_BUCKET+1))"
opts="--nb-meta1=${REPLICATION_DIRECTORY} --nb-meta2=${REPLICATION_BUCKET}"
for srvtype in ${AVOID} ; do opts="${opts} --no-${srvtype}"; done
${PREFIX}-bootstrap.py \
-B "$REPLICATION_BUCKET" \
Expand Down

0 comments on commit 8d33574

Please sign in to comment.