[srm-cvs] CVS Update: - Fix memory allocation problems

From: <d.rethans[@]jdimedia.nl>
Date: Thu Mar 13 2003 - 22:56:59 CET

Date: Thu Mar 13 22:56:58 CET 2003
User: Derick Rethans
Directory: srm/main/src

Log Message:
 [1.00]
 - Fix memory allocation problems
 
Modified files:
           srm/main/src/srm_client.c (version: 1.21)
           srm/main/src/srm_value.c (version: 1.51)
           srm/main/src/srm_value.h (version: 1.55)

[FILE: /srm/main/src/srm_client.c]

--- srm/main/src/srm_client.c:1.20 Thu Feb 20 06:04:11 2003 GMT
+++ srm/main/src/srm_client.c Thu Mar 13 20:56:58 2003 GMT
@@ -1,4 +1,4 @@
-/* $Id: cvstemp,v 1.20 2003/02/20 07:04:11 derick Exp $ */
+/* $Id: cvstemp,v 1.21 2003/03/13 21:56:58 derick Exp $ */
 
 /* The contents of this file are subject to the Vulcan Logic Public
  * License Version 1.1 (the "License"); you may not use this file
@@ -163,34 +163,21 @@
         srm_ui32 size = 0;
         struct srm_value* ret_val = NULL;
         srm_ui8* packet_d = NULL;
- struct srm_value* command = NULL;
- struct srm_value* command_val = NULL;
- srm_llist* parameters;
+ SRM_LIST(command);
 
         /* Create a list and srm_value */
- parameters = srm_llist_alloc(SRM_LLIST_VALUE_FREE);
- command = srm_value_init();
+ SRM_LIST_INIT(command);
 
         /* Adding the command name to the list */
- SRMVALP_SET_STR(command_val, strdup((char *) cmd));
- srm_llist_insert_next(parameters, NULL, (void *) command_val);
+ SRM_LIST_ADD(STR, command, (char *) cmd);
 
         /* Adding parameters to this list */
         if (NULL != params) {
- if (VALP_IS_LIST(params)) {
- srm_llist_insert_next (parameters, SRM_LLIST_TAIL (parameters), (void *) params);
- }
+ SRM_LIST_ADD_SVAL(command, params);
         }
- /* Setting command to the list */
- VALP_SET_LIST(command);
- SRMVALP_LIST(command) = (void *) parameters;
 
         serialize(command, (srm_ui8**) &packet_d, &size);
         clientlib_send_packet(connect_data, PKT_COMMAND, size, packet_d);
-
- if (NULL != params) {
- srm_llist_remove(parameters, SRM_LLIST_TAIL (parameters), (void *) NULL);
- }
         
         free(packet_d);
         srm_value_free(command);

[FILE: /srm/main/src/srm_value.c]

--- srm/main/src/srm_value.c:1.50 Sun Feb 16 12:02:19 2003 GMT
+++ srm/main/src/srm_value.c Thu Mar 13 20:56:58 2003 GMT
@@ -1,4 +1,4 @@
-/* $Id: cvstemp,v 1.50 2003/02/16 13:02:19 derick Exp $ */
+/* $Id: cvstemp,v 1.51 2003/03/13 21:56:58 derick Exp $ */
 
 /* The contents of this file are subject to the Vulcan Logic Public
  * License Version 1.1 (the "License"); you may not use this file
@@ -306,10 +306,9 @@
         if (NULL == value) {
                 return SRM_FAILED;
         }
- if (value->ref_count != 0) {
+ value->ref_count--;
+ if (value->ref_count >= 0) {
                 return SRM_SUCCESS;
- } else {
- value->ref_count--;
         }
         if (VALP_IS_STR(value)) {
                 free(SRMVALP_STR(value));
@@ -485,7 +484,7 @@
         srm_ui32 key_l;
 
         if (offset > d_length) {
- srm_error(ERROR_SERIALIZE, "deserialize: offset(%lu) larger then data block(%lu)", offset, d_length);
+ printf("deserialize: offset(%lu) larger then data block(%lu)", offset, d_length);
         }
         temp = (srm_value*) malloc(sizeof(srm_value));
         memset(temp, 0x00, sizeof(srm_value));

[FILE: /srm/main/src/srm_value.h]

--- srm/main/src/srm_value.h:1.54 Sun Feb 16 12:02:19 2003 GMT
+++ srm/main/src/srm_value.h Thu Mar 13 20:56:58 2003 GMT
@@ -1,4 +1,4 @@
-/* $Id: cvstemp,v 1.54 2003/02/16 13:02:19 derick Exp $ */
+/* $Id: cvstemp,v 1.55 2003/03/13 21:56:58 derick Exp $ */
 
 /* The contents of this file are subject to the Vulcan Logic Public
  * License Version 1.1 (the "License"); you may not use this file
@@ -122,6 +122,7 @@
 #define SRMVAL_U32(x) ((x).u32_value)
 #define SRMVAL_FLOAT(x) ((x).f_value)
 #define SRMVAL_STR(x) ((x).s_value)
+#define SRMVAL_STRLEN(x) ((x).value_length)
 #define SRMVAL_HASH(x) ((x).hash)
 #define SRMVAL_LIST(x) ((x).list)
 
@@ -130,6 +131,7 @@
 #define SRMVALP_U32(x) ((x)->u32_value)
 #define SRMVALP_FLOAT(x) ((x)->f_value)
 #define SRMVALP_STR(x) ((x)->s_value)
+#define SRMVALP_STRLEN(x) ((x)->value_length)
 #define SRMVALP_HASH(x) ((x)->hash)
 #define SRMVALP_LIST(x) ((x)->list)
 
@@ -184,7 +186,9 @@
         x->list = x##_ll; \
 }
 
-#define SRM_LIST_DESTROY(x) srm_llist_destroy (x##_ll)
+#define SRM_LIST_DESTROY(x) { \
+ srm_value_free(x); \
+}
 
 /* Do not touch these macro's!!! */
 #define SRM_LIST_ADD_BOOL(v,y) { \
@@ -208,8 +212,8 @@
         v->value_length = strlen(y); \
 }
 
-#define SRM_LIST_ADD_LIST(x,y) { \
- v->list = y##_ll; \
+#define SRM_LIST_ADD_LST(y,z) { \
+ srm_llist_insert_next((y##_ll), SRM_LLIST_TAIL((y##_ll)), (void *) z); \
 }
 
 /* You can use these macro's */
@@ -235,13 +239,13 @@
         v->s_value = malloc(l); \
         memcpy (v->s_value, y, l); \
         v->value_length = l; \
- srm_llist_insert_next((x##_ll), SRM_LLIST_TAIL((x##_ll)), (void *) v); \
+ srm_llist_insert_next((x##_ll), SRM_LLIST_TAIL(x##_ll), (void *) v); \
 }
 
-#define SRM_LIST_ADD_SVAL(x,y) { \
- struct srm_value* v; \
- v = srm_value_duplicate_shallow(y); \
- srm_llist_insert_next((x##_ll), SRM_LLIST_TAIL((x##_ll)), (void *) v); \
+#define SRM_LIST_ADD_SVAL(x,y) { \
+ srm_value *p = y; \
+ p->ref_count++; \
+ srm_llist_insert_next(x##_ll, SRM_LLIST_TAIL(x##_ll), (void *) p); \
 }
 
 #define SRM_LIST_FREE(x) { \
@@ -290,6 +294,10 @@
         struct srm_value* v; \
         v = srm_value_duplicate_shallow(y); \
         srm_hash_index_add((x##_hash),k,(void*)v); \
+}
+
+#define SRM_HASH_ADD_LST(y,k,l,v) { \
+ srm_hash_add((y##_hash),k,l,(void*)v); \
 }
 
 /* Macro's to add elements to a hash defined by a string key */
Received on Thu Mar 13 22:57:03 2003

This archive was generated by hypermail 2.1.8 : Tue Jan 06 2009 - 03:00:03 CET