Index: pjproject/trunk/pjlib/src/pj/pool.c
===================================================================
--- pjproject/trunk/pjlib/src/pj/pool.c	(revision 3080)
+++ pjproject/trunk/pjlib/src/pj/pool.c	(revision 3081)
@@ -213,6 +213,12 @@
     /* Create the first block from the memory. */
     block = (pj_pool_block*) (buffer + sizeof(*pool));
-    block->cur = block->buf = ((unsigned char*)block) + sizeof(pj_pool_block);
+    block->buf = ((unsigned char*)block) + sizeof(pj_pool_block);
     block->end = buffer + initial_size;
+
+    /* Set the start pointer, aligning it as needed */
+    block->cur = (unsigned char*)
+                 (((unsigned long)block->buf + PJ_POOL_ALIGNMENT - 1) &
+                  ~(PJ_POOL_ALIGNMENT - 1));
+
     pj_list_insert_after(&pool->block_list, block);
 
@@ -255,5 +261,10 @@
 
     block = pool->block_list.next;
-    block->cur = block->buf;
+
+    /* Set the start pointer, aligning it as needed */
+    block->cur = (unsigned char*)
+                 (((unsigned long)block->buf + PJ_POOL_ALIGNMENT - 1) &
+                  ~(PJ_POOL_ALIGNMENT - 1));
+
     pool->capacity = block->end - (unsigned char*)pool;
 }
Index: pjproject/trunk/pjlib/src/pjlib-test/pool.c
===================================================================
--- pjproject/trunk/pjlib/src/pjlib-test/pool.c	(revision 3080)
+++ pjproject/trunk/pjlib/src/pjlib-test/pool.c	(revision 3081)
@@ -77,4 +77,110 @@
 
     pj_pool_release(pool);
+    return 0;
+}
+
+/* Test that the alignment works. */
+static int pool_alignment_test(void)
+{
+    pj_pool_t *pool;
+    void *ptr;
+
+    PJ_LOG(3,("test", "...alignment test"));
+
+    pool = pj_pool_create(mem, NULL, PJ_POOL_SIZE+64, 64, NULL);
+    if (!pool)
+	return -300;
+
+#define IS_ALIGNED(p)	((((unsigned long)p) & (PJ_POOL_ALIGNMENT-1)) == 0)
+
+    /* Test first allocation */
+    ptr = pj_pool_alloc(pool, 1);
+    if (!IS_ALIGNED(ptr)) {
+	pj_pool_release(pool);
+	return -310;
+    }
+
+    /* Test subsequent allocation */
+    ptr = pj_pool_alloc(pool, 1);
+    if (!IS_ALIGNED(ptr)) {
+	pj_pool_release(pool);
+	return -320;
+    }
+
+    /* Test allocation after new block is created */
+    ptr = pj_pool_alloc(pool, 127);
+    if (!IS_ALIGNED(ptr)) {
+	pj_pool_release(pool);
+	return -330;
+    }
+
+    /* Reset the pool */
+    pj_pool_reset(pool);
+
+    /* Retest first allocation */
+    ptr = pj_pool_alloc(pool, 1);
+    if (!IS_ALIGNED(ptr)) {
+	pj_pool_release(pool);
+	return -340;
+    }
+
+    /* Retest subsequent allocation */
+    ptr = pj_pool_alloc(pool, 1);
+    if (!IS_ALIGNED(ptr)) {
+	pj_pool_release(pool);
+	return -350;
+    }
+
+    /* Done */
+    pj_pool_release(pool);
+
+    return 0;
+}
+
+/* Test that the alignment works for pool on buf. */
+static int pool_buf_alignment_test(void)
+{
+    pj_pool_t *pool;
+    char buf[256];
+    void *ptr;
+
+    PJ_LOG(3,("test", "...pool_buf alignment test"));
+
+    pool = pj_pool_create_on_buf(NULL, buf, sizeof(buf));
+    if (!pool)
+	return -400;
+
+    /* Test first allocation */
+    ptr = pj_pool_alloc(pool, 1);
+    if (!IS_ALIGNED(ptr)) {
+	pj_pool_release(pool);
+	return -410;
+    }
+
+    /* Test subsequent allocation */
+    ptr = pj_pool_alloc(pool, 1);
+    if (!IS_ALIGNED(ptr)) {
+	pj_pool_release(pool);
+	return -420;
+    }
+
+    /* Reset the pool */
+    pj_pool_reset(pool);
+
+    /* Retest first allocation */
+    ptr = pj_pool_alloc(pool, 1);
+    if (!IS_ALIGNED(ptr)) {
+	pj_pool_release(pool);
+	return -430;
+    }
+
+    /* Retest subsequent allocation */
+    ptr = pj_pool_alloc(pool, 1);
+    if (!IS_ALIGNED(ptr)) {
+	pj_pool_release(pool);
+	return -440;
+    }
+
+    /* Done */
     return 0;
 }
@@ -150,5 +256,5 @@
     /* 16 is the internal struct in pool_buf */
     static char buf[ STATIC_BUF_SIZE + sizeof(pj_pool_t) + 
-		     sizeof(pj_pool_block) + 16];
+		     sizeof(pj_pool_block) + 2 * PJ_POOL_ALIGNMENT];
     pj_pool_t *pool;
     void *p;
@@ -201,4 +307,10 @@
     if (rc) return rc;
 
+    rc = pool_alignment_test();
+    if (rc) return rc;
+
+    rc = pool_buf_alignment_test();
+    if (rc) return rc;
+
     for (loop=0; loop<LOOP; ++loop) {
 	/* Test that the pool should grow automaticly. */
Index: pjproject/trunk/pjlib/src/pjlib-test/pool_perf.c
===================================================================
--- pjproject/trunk/pjlib/src/pjlib-test/pool_perf.c	(revision 3080)
+++ pjproject/trunk/pjlib/src/pjlib-test/pool_perf.c	(revision 3081)
@@ -128,6 +128,10 @@
     /* Initialize size of chunks to allocate in for the test. */
     for (i=0; i<COUNT; ++i) {
+	unsigned aligned_size;
 	sizes[i] = MIN_SIZE + (pj_rand() % MAX_SIZE);
-	total_size += sizes[i];
+	aligned_size = sizes[i];
+	if (aligned_size & (PJ_POOL_ALIGNMENT-1))
+	    aligned_size = ((aligned_size + PJ_POOL_ALIGNMENT - 1)) & ~(PJ_POOL_ALIGNMENT - 1);
+	total_size += aligned_size;
     }
 
